2 * libata-core.c - helper library for ATA
4 * Maintained by: Jeff Garzik <jgarzik@pobox.com>
5 * Please ALWAYS copy linux-ide@vger.kernel.org
8 * Copyright 2003-2004 Red Hat, Inc. All rights reserved.
9 * Copyright 2003-2004 Jeff Garzik
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; see the file COPYING. If not, write to
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 * libata documentation is available via 'make {ps|pdf}docs',
28 * as Documentation/DocBook/libata.*
30 * Hardware documentation available from http://www.t13.org/ and
31 * http://www.sata-io.org/
35 #include <linux/kernel.h>
36 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/init.h>
39 #include <linux/list.h>
41 #include <linux/highmem.h>
42 #include <linux/spinlock.h>
43 #include <linux/blkdev.h>
44 #include <linux/delay.h>
45 #include <linux/timer.h>
46 #include <linux/interrupt.h>
47 #include <linux/completion.h>
48 #include <linux/suspend.h>
49 #include <linux/workqueue.h>
50 #include <linux/jiffies.h>
51 #include <linux/scatterlist.h>
52 #include <scsi/scsi.h>
53 #include <scsi/scsi_cmnd.h>
54 #include <scsi/scsi_host.h>
55 #include <linux/libata.h>
57 #include <asm/semaphore.h>
58 #include <asm/byteorder.h>
62 #define DRV_VERSION "2.21" /* must be exactly four chars */
65 /* debounce timing parameters in msecs { interval, duration, timeout } */
66 const unsigned long sata_deb_timing_normal
[] = { 5, 100, 2000 };
67 const unsigned long sata_deb_timing_hotplug
[] = { 25, 500, 2000 };
68 const unsigned long sata_deb_timing_long
[] = { 100, 2000, 5000 };
70 static unsigned int ata_dev_init_params(struct ata_device
*dev
,
71 u16 heads
, u16 sectors
);
72 static unsigned int ata_dev_set_xfermode(struct ata_device
*dev
);
73 static void ata_dev_xfermask(struct ata_device
*dev
);
74 static unsigned long ata_dev_blacklisted(const struct ata_device
*dev
);
76 unsigned int ata_print_id
= 1;
77 static struct workqueue_struct
*ata_wq
;
79 struct workqueue_struct
*ata_aux_wq
;
81 int atapi_enabled
= 1;
82 module_param(atapi_enabled
, int, 0444);
83 MODULE_PARM_DESC(atapi_enabled
, "Enable discovery of ATAPI devices (0=off, 1=on)");
86 module_param(atapi_dmadir
, int, 0444);
87 MODULE_PARM_DESC(atapi_dmadir
, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");
89 int atapi_passthru16
= 1;
90 module_param(atapi_passthru16
, int, 0444);
91 MODULE_PARM_DESC(atapi_passthru16
, "Enable ATA_16 passthru for ATAPI devices; on by default (0=off, 1=on)");
94 module_param_named(fua
, libata_fua
, int, 0444);
95 MODULE_PARM_DESC(fua
, "FUA support (0=off, 1=on)");
97 static int ata_ignore_hpa
= 0;
98 module_param_named(ignore_hpa
, ata_ignore_hpa
, int, 0644);
99 MODULE_PARM_DESC(ignore_hpa
, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)");
101 static int ata_probe_timeout
= ATA_TMOUT_INTERNAL
/ HZ
;
102 module_param(ata_probe_timeout
, int, 0444);
103 MODULE_PARM_DESC(ata_probe_timeout
, "Set ATA probing timeout (seconds)");
105 int libata_noacpi
= 1;
106 module_param_named(noacpi
, libata_noacpi
, int, 0444);
107 MODULE_PARM_DESC(noacpi
, "Disables the use of ACPI in suspend/resume when set");
109 MODULE_AUTHOR("Jeff Garzik");
110 MODULE_DESCRIPTION("Library module for ATA devices");
111 MODULE_LICENSE("GPL");
112 MODULE_VERSION(DRV_VERSION
);
116 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
117 * @tf: Taskfile to convert
118 * @pmp: Port multiplier port
119 * @is_cmd: This FIS is for command
120 * @fis: Buffer into which data will output
122 * Converts a standard ATA taskfile to a Serial ATA
123 * FIS structure (Register - Host to Device).
126 * Inherited from caller.
128 void ata_tf_to_fis(const struct ata_taskfile
*tf
, u8 pmp
, int is_cmd
, u8
*fis
)
130 fis
[0] = 0x27; /* Register - Host to Device FIS */
131 fis
[1] = pmp
& 0xf; /* Port multiplier number*/
133 fis
[1] |= (1 << 7); /* bit 7 indicates Command FIS */
135 fis
[2] = tf
->command
;
136 fis
[3] = tf
->feature
;
143 fis
[8] = tf
->hob_lbal
;
144 fis
[9] = tf
->hob_lbam
;
145 fis
[10] = tf
->hob_lbah
;
146 fis
[11] = tf
->hob_feature
;
149 fis
[13] = tf
->hob_nsect
;
160 * ata_tf_from_fis - Convert SATA FIS to ATA taskfile
161 * @fis: Buffer from which data will be input
162 * @tf: Taskfile to output
164 * Converts a serial ATA FIS structure to a standard ATA taskfile.
167 * Inherited from caller.
170 void ata_tf_from_fis(const u8
*fis
, struct ata_taskfile
*tf
)
172 tf
->command
= fis
[2]; /* status */
173 tf
->feature
= fis
[3]; /* error */
180 tf
->hob_lbal
= fis
[8];
181 tf
->hob_lbam
= fis
[9];
182 tf
->hob_lbah
= fis
[10];
185 tf
->hob_nsect
= fis
[13];
188 static const u8 ata_rw_cmds
[] = {
192 ATA_CMD_READ_MULTI_EXT
,
193 ATA_CMD_WRITE_MULTI_EXT
,
197 ATA_CMD_WRITE_MULTI_FUA_EXT
,
201 ATA_CMD_PIO_READ_EXT
,
202 ATA_CMD_PIO_WRITE_EXT
,
215 ATA_CMD_WRITE_FUA_EXT
219 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
220 * @tf: command to examine and configure
221 * @dev: device tf belongs to
223 * Examine the device configuration and tf->flags to calculate
224 * the proper read/write commands and protocol to use.
229 static int ata_rwcmd_protocol(struct ata_taskfile
*tf
, struct ata_device
*dev
)
233 int index
, fua
, lba48
, write
;
235 fua
= (tf
->flags
& ATA_TFLAG_FUA
) ? 4 : 0;
236 lba48
= (tf
->flags
& ATA_TFLAG_LBA48
) ? 2 : 0;
237 write
= (tf
->flags
& ATA_TFLAG_WRITE
) ? 1 : 0;
239 if (dev
->flags
& ATA_DFLAG_PIO
) {
240 tf
->protocol
= ATA_PROT_PIO
;
241 index
= dev
->multi_count
? 0 : 8;
242 } else if (lba48
&& (dev
->link
->ap
->flags
& ATA_FLAG_PIO_LBA48
)) {
243 /* Unable to use DMA due to host limitation */
244 tf
->protocol
= ATA_PROT_PIO
;
245 index
= dev
->multi_count
? 0 : 8;
247 tf
->protocol
= ATA_PROT_DMA
;
251 cmd
= ata_rw_cmds
[index
+ fua
+ lba48
+ write
];
260 * ata_tf_read_block - Read block address from ATA taskfile
261 * @tf: ATA taskfile of interest
262 * @dev: ATA device @tf belongs to
267 * Read block address from @tf. This function can handle all
268 * three address formats - LBA, LBA48 and CHS. tf->protocol and
269 * flags select the address format to use.
272 * Block address read from @tf.
274 u64
ata_tf_read_block(struct ata_taskfile
*tf
, struct ata_device
*dev
)
278 if (tf
->flags
& ATA_TFLAG_LBA
) {
279 if (tf
->flags
& ATA_TFLAG_LBA48
) {
280 block
|= (u64
)tf
->hob_lbah
<< 40;
281 block
|= (u64
)tf
->hob_lbam
<< 32;
282 block
|= tf
->hob_lbal
<< 24;
284 block
|= (tf
->device
& 0xf) << 24;
286 block
|= tf
->lbah
<< 16;
287 block
|= tf
->lbam
<< 8;
292 cyl
= tf
->lbam
| (tf
->lbah
<< 8);
293 head
= tf
->device
& 0xf;
296 block
= (cyl
* dev
->heads
+ head
) * dev
->sectors
+ sect
;
303 * ata_build_rw_tf - Build ATA taskfile for given read/write request
304 * @tf: Target ATA taskfile
305 * @dev: ATA device @tf belongs to
306 * @block: Block address
307 * @n_block: Number of blocks
308 * @tf_flags: RW/FUA etc...
314 * Build ATA taskfile @tf for read/write request described by
315 * @block, @n_block, @tf_flags and @tag on @dev.
319 * 0 on success, -ERANGE if the request is too large for @dev,
320 * -EINVAL if the request is invalid.
322 int ata_build_rw_tf(struct ata_taskfile
*tf
, struct ata_device
*dev
,
323 u64 block
, u32 n_block
, unsigned int tf_flags
,
326 tf
->flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
327 tf
->flags
|= tf_flags
;
329 if (ata_ncq_enabled(dev
) && likely(tag
!= ATA_TAG_INTERNAL
)) {
331 if (!lba_48_ok(block
, n_block
))
334 tf
->protocol
= ATA_PROT_NCQ
;
335 tf
->flags
|= ATA_TFLAG_LBA
| ATA_TFLAG_LBA48
;
337 if (tf
->flags
& ATA_TFLAG_WRITE
)
338 tf
->command
= ATA_CMD_FPDMA_WRITE
;
340 tf
->command
= ATA_CMD_FPDMA_READ
;
342 tf
->nsect
= tag
<< 3;
343 tf
->hob_feature
= (n_block
>> 8) & 0xff;
344 tf
->feature
= n_block
& 0xff;
346 tf
->hob_lbah
= (block
>> 40) & 0xff;
347 tf
->hob_lbam
= (block
>> 32) & 0xff;
348 tf
->hob_lbal
= (block
>> 24) & 0xff;
349 tf
->lbah
= (block
>> 16) & 0xff;
350 tf
->lbam
= (block
>> 8) & 0xff;
351 tf
->lbal
= block
& 0xff;
354 if (tf
->flags
& ATA_TFLAG_FUA
)
355 tf
->device
|= 1 << 7;
356 } else if (dev
->flags
& ATA_DFLAG_LBA
) {
357 tf
->flags
|= ATA_TFLAG_LBA
;
359 if (lba_28_ok(block
, n_block
)) {
361 tf
->device
|= (block
>> 24) & 0xf;
362 } else if (lba_48_ok(block
, n_block
)) {
363 if (!(dev
->flags
& ATA_DFLAG_LBA48
))
367 tf
->flags
|= ATA_TFLAG_LBA48
;
369 tf
->hob_nsect
= (n_block
>> 8) & 0xff;
371 tf
->hob_lbah
= (block
>> 40) & 0xff;
372 tf
->hob_lbam
= (block
>> 32) & 0xff;
373 tf
->hob_lbal
= (block
>> 24) & 0xff;
375 /* request too large even for LBA48 */
378 if (unlikely(ata_rwcmd_protocol(tf
, dev
) < 0))
381 tf
->nsect
= n_block
& 0xff;
383 tf
->lbah
= (block
>> 16) & 0xff;
384 tf
->lbam
= (block
>> 8) & 0xff;
385 tf
->lbal
= block
& 0xff;
387 tf
->device
|= ATA_LBA
;
390 u32 sect
, head
, cyl
, track
;
392 /* The request -may- be too large for CHS addressing. */
393 if (!lba_28_ok(block
, n_block
))
396 if (unlikely(ata_rwcmd_protocol(tf
, dev
) < 0))
399 /* Convert LBA to CHS */
400 track
= (u32
)block
/ dev
->sectors
;
401 cyl
= track
/ dev
->heads
;
402 head
= track
% dev
->heads
;
403 sect
= (u32
)block
% dev
->sectors
+ 1;
405 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
406 (u32
)block
, track
, cyl
, head
, sect
);
408 /* Check whether the converted CHS can fit.
412 if ((cyl
>> 16) || (head
>> 4) || (sect
>> 8) || (!sect
))
415 tf
->nsect
= n_block
& 0xff; /* Sector count 0 means 256 sectors */
426 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
427 * @pio_mask: pio_mask
428 * @mwdma_mask: mwdma_mask
429 * @udma_mask: udma_mask
431 * Pack @pio_mask, @mwdma_mask and @udma_mask into a single
432 * unsigned int xfer_mask.
440 static unsigned int ata_pack_xfermask(unsigned int pio_mask
,
441 unsigned int mwdma_mask
,
442 unsigned int udma_mask
)
444 return ((pio_mask
<< ATA_SHIFT_PIO
) & ATA_MASK_PIO
) |
445 ((mwdma_mask
<< ATA_SHIFT_MWDMA
) & ATA_MASK_MWDMA
) |
446 ((udma_mask
<< ATA_SHIFT_UDMA
) & ATA_MASK_UDMA
);
450 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
451 * @xfer_mask: xfer_mask to unpack
452 * @pio_mask: resulting pio_mask
453 * @mwdma_mask: resulting mwdma_mask
454 * @udma_mask: resulting udma_mask
456 * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask.
457 * Any NULL distination masks will be ignored.
459 static void ata_unpack_xfermask(unsigned int xfer_mask
,
460 unsigned int *pio_mask
,
461 unsigned int *mwdma_mask
,
462 unsigned int *udma_mask
)
465 *pio_mask
= (xfer_mask
& ATA_MASK_PIO
) >> ATA_SHIFT_PIO
;
467 *mwdma_mask
= (xfer_mask
& ATA_MASK_MWDMA
) >> ATA_SHIFT_MWDMA
;
469 *udma_mask
= (xfer_mask
& ATA_MASK_UDMA
) >> ATA_SHIFT_UDMA
;
472 static const struct ata_xfer_ent
{
476 { ATA_SHIFT_PIO
, ATA_BITS_PIO
, XFER_PIO_0
},
477 { ATA_SHIFT_MWDMA
, ATA_BITS_MWDMA
, XFER_MW_DMA_0
},
478 { ATA_SHIFT_UDMA
, ATA_BITS_UDMA
, XFER_UDMA_0
},
483 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
484 * @xfer_mask: xfer_mask of interest
486 * Return matching XFER_* value for @xfer_mask. Only the highest
487 * bit of @xfer_mask is considered.
493 * Matching XFER_* value, 0 if no match found.
495 static u8
ata_xfer_mask2mode(unsigned int xfer_mask
)
497 int highbit
= fls(xfer_mask
) - 1;
498 const struct ata_xfer_ent
*ent
;
500 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
501 if (highbit
>= ent
->shift
&& highbit
< ent
->shift
+ ent
->bits
)
502 return ent
->base
+ highbit
- ent
->shift
;
507 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
508 * @xfer_mode: XFER_* of interest
510 * Return matching xfer_mask for @xfer_mode.
516 * Matching xfer_mask, 0 if no match found.
518 static unsigned int ata_xfer_mode2mask(u8 xfer_mode
)
520 const struct ata_xfer_ent
*ent
;
522 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
523 if (xfer_mode
>= ent
->base
&& xfer_mode
< ent
->base
+ ent
->bits
)
524 return 1 << (ent
->shift
+ xfer_mode
- ent
->base
);
529 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
530 * @xfer_mode: XFER_* of interest
532 * Return matching xfer_shift for @xfer_mode.
538 * Matching xfer_shift, -1 if no match found.
540 static int ata_xfer_mode2shift(unsigned int xfer_mode
)
542 const struct ata_xfer_ent
*ent
;
544 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
545 if (xfer_mode
>= ent
->base
&& xfer_mode
< ent
->base
+ ent
->bits
)
551 * ata_mode_string - convert xfer_mask to string
552 * @xfer_mask: mask of bits supported; only highest bit counts.
554 * Determine string which represents the highest speed
555 * (highest bit in @modemask).
561 * Constant C string representing highest speed listed in
562 * @mode_mask, or the constant C string "<n/a>".
564 static const char *ata_mode_string(unsigned int xfer_mask
)
566 static const char * const xfer_mode_str
[] = {
590 highbit
= fls(xfer_mask
) - 1;
591 if (highbit
>= 0 && highbit
< ARRAY_SIZE(xfer_mode_str
))
592 return xfer_mode_str
[highbit
];
596 static const char *sata_spd_string(unsigned int spd
)
598 static const char * const spd_str
[] = {
603 if (spd
== 0 || (spd
- 1) >= ARRAY_SIZE(spd_str
))
605 return spd_str
[spd
- 1];
608 void ata_dev_disable(struct ata_device
*dev
)
610 if (ata_dev_enabled(dev
)) {
611 if (ata_msg_drv(dev
->link
->ap
))
612 ata_dev_printk(dev
, KERN_WARNING
, "disabled\n");
613 ata_down_xfermask_limit(dev
, ATA_DNXFER_FORCE_PIO0
|
620 * ata_devchk - PATA device presence detection
621 * @ap: ATA channel to examine
622 * @device: Device to examine (starting at zero)
624 * This technique was originally described in
625 * Hale Landis's ATADRVR (www.ata-atapi.com), and
626 * later found its way into the ATA/ATAPI spec.
628 * Write a pattern to the ATA shadow registers,
629 * and if a device is present, it will respond by
630 * correctly storing and echoing back the
631 * ATA shadow register contents.
637 static unsigned int ata_devchk(struct ata_port
*ap
, unsigned int device
)
639 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
642 ap
->ops
->dev_select(ap
, device
);
644 iowrite8(0x55, ioaddr
->nsect_addr
);
645 iowrite8(0xaa, ioaddr
->lbal_addr
);
647 iowrite8(0xaa, ioaddr
->nsect_addr
);
648 iowrite8(0x55, ioaddr
->lbal_addr
);
650 iowrite8(0x55, ioaddr
->nsect_addr
);
651 iowrite8(0xaa, ioaddr
->lbal_addr
);
653 nsect
= ioread8(ioaddr
->nsect_addr
);
654 lbal
= ioread8(ioaddr
->lbal_addr
);
656 if ((nsect
== 0x55) && (lbal
== 0xaa))
657 return 1; /* we found a device */
659 return 0; /* nothing found */
663 * ata_dev_classify - determine device type based on ATA-spec signature
664 * @tf: ATA taskfile register set for device to be identified
666 * Determine from taskfile register contents whether a device is
667 * ATA or ATAPI, as per "Signature and persistence" section
668 * of ATA/PI spec (volume 1, sect 5.14).
674 * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, or %ATA_DEV_UNKNOWN
675 * the event of failure.
678 unsigned int ata_dev_classify(const struct ata_taskfile
*tf
)
680 /* Apple's open source Darwin code hints that some devices only
681 * put a proper signature into the LBA mid/high registers,
682 * So, we only check those. It's sufficient for uniqueness.
685 if (((tf
->lbam
== 0) && (tf
->lbah
== 0)) ||
686 ((tf
->lbam
== 0x3c) && (tf
->lbah
== 0xc3))) {
687 DPRINTK("found ATA device by sig\n");
691 if (((tf
->lbam
== 0x14) && (tf
->lbah
== 0xeb)) ||
692 ((tf
->lbam
== 0x69) && (tf
->lbah
== 0x96))) {
693 DPRINTK("found ATAPI device by sig\n");
694 return ATA_DEV_ATAPI
;
697 DPRINTK("unknown device\n");
698 return ATA_DEV_UNKNOWN
;
702 * ata_dev_try_classify - Parse returned ATA device signature
703 * @ap: ATA channel to examine
704 * @device: Device to examine (starting at zero)
705 * @r_err: Value of error register on completion
707 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
708 * an ATA/ATAPI-defined set of values is placed in the ATA
709 * shadow registers, indicating the results of device detection
712 * Select the ATA device, and read the values from the ATA shadow
713 * registers. Then parse according to the Error register value,
714 * and the spec-defined values examined by ata_dev_classify().
720 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
724 ata_dev_try_classify(struct ata_port
*ap
, unsigned int device
, u8
*r_err
)
726 struct ata_taskfile tf
;
730 ap
->ops
->dev_select(ap
, device
);
732 memset(&tf
, 0, sizeof(tf
));
734 ap
->ops
->tf_read(ap
, &tf
);
739 /* see if device passed diags: if master then continue and warn later */
740 if (err
== 0 && device
== 0)
741 /* diagnostic fail : do nothing _YET_ */
742 ap
->link
.device
[device
].horkage
|= ATA_HORKAGE_DIAGNOSTIC
;
745 else if ((device
== 0) && (err
== 0x81))
750 /* determine if device is ATA or ATAPI */
751 class = ata_dev_classify(&tf
);
753 if (class == ATA_DEV_UNKNOWN
)
755 if ((class == ATA_DEV_ATA
) && (ata_chk_status(ap
) == 0))
761 * ata_id_string - Convert IDENTIFY DEVICE page into string
762 * @id: IDENTIFY DEVICE results we will examine
763 * @s: string into which data is output
764 * @ofs: offset into identify device page
765 * @len: length of string to return. must be an even number.
767 * The strings in the IDENTIFY DEVICE page are broken up into
768 * 16-bit chunks. Run through the string, and output each
769 * 8-bit chunk linearly, regardless of platform.
775 void ata_id_string(const u16
*id
, unsigned char *s
,
776 unsigned int ofs
, unsigned int len
)
795 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
796 * @id: IDENTIFY DEVICE results we will examine
797 * @s: string into which data is output
798 * @ofs: offset into identify device page
799 * @len: length of string to return. must be an odd number.
801 * This function is identical to ata_id_string except that it
802 * trims trailing spaces and terminates the resulting string with
803 * null. @len must be actual maximum length (even number) + 1.
808 void ata_id_c_string(const u16
*id
, unsigned char *s
,
809 unsigned int ofs
, unsigned int len
)
815 ata_id_string(id
, s
, ofs
, len
- 1);
817 p
= s
+ strnlen(s
, len
- 1);
818 while (p
> s
&& p
[-1] == ' ')
823 static u64
ata_tf_to_lba48(struct ata_taskfile
*tf
)
827 sectors
|= ((u64
)(tf
->hob_lbah
& 0xff)) << 40;
828 sectors
|= ((u64
)(tf
->hob_lbam
& 0xff)) << 32;
829 sectors
|= (tf
->hob_lbal
& 0xff) << 24;
830 sectors
|= (tf
->lbah
& 0xff) << 16;
831 sectors
|= (tf
->lbam
& 0xff) << 8;
832 sectors
|= (tf
->lbal
& 0xff);
837 static u64
ata_tf_to_lba(struct ata_taskfile
*tf
)
841 sectors
|= (tf
->device
& 0x0f) << 24;
842 sectors
|= (tf
->lbah
& 0xff) << 16;
843 sectors
|= (tf
->lbam
& 0xff) << 8;
844 sectors
|= (tf
->lbal
& 0xff);
850 * ata_read_native_max_address_ext - LBA48 native max query
851 * @dev: Device to query
853 * Perform an LBA48 size query upon the device in question. Return the
854 * actual LBA48 size or zero if the command fails.
857 static u64
ata_read_native_max_address_ext(struct ata_device
*dev
)
860 struct ata_taskfile tf
;
862 ata_tf_init(dev
, &tf
);
864 tf
.command
= ATA_CMD_READ_NATIVE_MAX_EXT
;
865 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_LBA48
| ATA_TFLAG_ISADDR
;
866 tf
.protocol
|= ATA_PROT_NODATA
;
869 err
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
873 return ata_tf_to_lba48(&tf
);
877 * ata_read_native_max_address - LBA28 native max query
878 * @dev: Device to query
880 * Performa an LBA28 size query upon the device in question. Return the
881 * actual LBA28 size or zero if the command fails.
884 static u64
ata_read_native_max_address(struct ata_device
*dev
)
887 struct ata_taskfile tf
;
889 ata_tf_init(dev
, &tf
);
891 tf
.command
= ATA_CMD_READ_NATIVE_MAX
;
892 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_ISADDR
;
893 tf
.protocol
|= ATA_PROT_NODATA
;
896 err
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
900 return ata_tf_to_lba(&tf
);
904 * ata_set_native_max_address_ext - LBA48 native max set
905 * @dev: Device to query
906 * @new_sectors: new max sectors value to set for the device
908 * Perform an LBA48 size set max upon the device in question. Return the
909 * actual LBA48 size or zero if the command fails.
912 static u64
ata_set_native_max_address_ext(struct ata_device
*dev
, u64 new_sectors
)
915 struct ata_taskfile tf
;
919 ata_tf_init(dev
, &tf
);
921 tf
.command
= ATA_CMD_SET_MAX_EXT
;
922 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_LBA48
| ATA_TFLAG_ISADDR
;
923 tf
.protocol
|= ATA_PROT_NODATA
;
926 tf
.lbal
= (new_sectors
>> 0) & 0xff;
927 tf
.lbam
= (new_sectors
>> 8) & 0xff;
928 tf
.lbah
= (new_sectors
>> 16) & 0xff;
930 tf
.hob_lbal
= (new_sectors
>> 24) & 0xff;
931 tf
.hob_lbam
= (new_sectors
>> 32) & 0xff;
932 tf
.hob_lbah
= (new_sectors
>> 40) & 0xff;
934 err
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
938 return ata_tf_to_lba48(&tf
);
942 * ata_set_native_max_address - LBA28 native max set
943 * @dev: Device to query
944 * @new_sectors: new max sectors value to set for the device
946 * Perform an LBA28 size set max upon the device in question. Return the
947 * actual LBA28 size or zero if the command fails.
950 static u64
ata_set_native_max_address(struct ata_device
*dev
, u64 new_sectors
)
953 struct ata_taskfile tf
;
957 ata_tf_init(dev
, &tf
);
959 tf
.command
= ATA_CMD_SET_MAX
;
960 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_ISADDR
;
961 tf
.protocol
|= ATA_PROT_NODATA
;
963 tf
.lbal
= (new_sectors
>> 0) & 0xff;
964 tf
.lbam
= (new_sectors
>> 8) & 0xff;
965 tf
.lbah
= (new_sectors
>> 16) & 0xff;
966 tf
.device
|= ((new_sectors
>> 24) & 0x0f) | 0x40;
968 err
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
972 return ata_tf_to_lba(&tf
);
976 * ata_hpa_resize - Resize a device with an HPA set
977 * @dev: Device to resize
979 * Read the size of an LBA28 or LBA48 disk with HPA features and resize
980 * it if required to the full size of the media. The caller must check
981 * the drive has the HPA feature set enabled.
984 static u64
ata_hpa_resize(struct ata_device
*dev
)
986 u64 sectors
= dev
->n_sectors
;
989 if (ata_id_has_lba48(dev
->id
))
990 hpa_sectors
= ata_read_native_max_address_ext(dev
);
992 hpa_sectors
= ata_read_native_max_address(dev
);
994 if (hpa_sectors
> sectors
) {
995 ata_dev_printk(dev
, KERN_INFO
,
996 "Host Protected Area detected:\n"
997 "\tcurrent size: %lld sectors\n"
998 "\tnative size: %lld sectors\n",
999 (long long)sectors
, (long long)hpa_sectors
);
1001 if (ata_ignore_hpa
) {
1002 if (ata_id_has_lba48(dev
->id
))
1003 hpa_sectors
= ata_set_native_max_address_ext(dev
, hpa_sectors
);
1005 hpa_sectors
= ata_set_native_max_address(dev
,
1009 ata_dev_printk(dev
, KERN_INFO
, "native size "
1010 "increased to %lld sectors\n",
1011 (long long)hpa_sectors
);
1015 } else if (hpa_sectors
< sectors
)
1016 ata_dev_printk(dev
, KERN_WARNING
, "%s 1: hpa sectors (%lld) "
1017 "is smaller than sectors (%lld)\n", __FUNCTION__
,
1018 (long long)hpa_sectors
, (long long)sectors
);
1023 static u64
ata_id_n_sectors(const u16
*id
)
1025 if (ata_id_has_lba(id
)) {
1026 if (ata_id_has_lba48(id
))
1027 return ata_id_u64(id
, 100);
1029 return ata_id_u32(id
, 60);
1031 if (ata_id_current_chs_valid(id
))
1032 return ata_id_u32(id
, 57);
1034 return id
[1] * id
[3] * id
[6];
1039 * ata_id_to_dma_mode - Identify DMA mode from id block
1040 * @dev: device to identify
1041 * @unknown: mode to assume if we cannot tell
1043 * Set up the timing values for the device based upon the identify
1044 * reported values for the DMA mode. This function is used by drivers
1045 * which rely upon firmware configured modes, but wish to report the
1046 * mode correctly when possible.
1048 * In addition we emit similarly formatted messages to the default
1049 * ata_dev_set_mode handler, in order to provide consistency of
1053 void ata_id_to_dma_mode(struct ata_device
*dev
, u8 unknown
)
1058 /* Pack the DMA modes */
1059 mask
= ((dev
->id
[63] >> 8) << ATA_SHIFT_MWDMA
) & ATA_MASK_MWDMA
;
1060 if (dev
->id
[53] & 0x04)
1061 mask
|= ((dev
->id
[88] >> 8) << ATA_SHIFT_UDMA
) & ATA_MASK_UDMA
;
1063 /* Select the mode in use */
1064 mode
= ata_xfer_mask2mode(mask
);
1067 ata_dev_printk(dev
, KERN_INFO
, "configured for %s\n",
1068 ata_mode_string(mask
));
1070 /* SWDMA perhaps ? */
1072 ata_dev_printk(dev
, KERN_INFO
, "configured for DMA\n");
1075 /* Configure the device reporting */
1076 dev
->xfer_mode
= mode
;
1077 dev
->xfer_shift
= ata_xfer_mode2shift(mode
);
1081 * ata_noop_dev_select - Select device 0/1 on ATA bus
1082 * @ap: ATA channel to manipulate
1083 * @device: ATA device (numbered from zero) to select
1085 * This function performs no actual function.
1087 * May be used as the dev_select() entry in ata_port_operations.
1092 void ata_noop_dev_select (struct ata_port
*ap
, unsigned int device
)
1098 * ata_std_dev_select - Select device 0/1 on ATA bus
1099 * @ap: ATA channel to manipulate
1100 * @device: ATA device (numbered from zero) to select
1102 * Use the method defined in the ATA specification to
1103 * make either device 0, or device 1, active on the
1104 * ATA channel. Works with both PIO and MMIO.
1106 * May be used as the dev_select() entry in ata_port_operations.
1112 void ata_std_dev_select (struct ata_port
*ap
, unsigned int device
)
1117 tmp
= ATA_DEVICE_OBS
;
1119 tmp
= ATA_DEVICE_OBS
| ATA_DEV1
;
1121 iowrite8(tmp
, ap
->ioaddr
.device_addr
);
1122 ata_pause(ap
); /* needed; also flushes, for mmio */
1126 * ata_dev_select - Select device 0/1 on ATA bus
1127 * @ap: ATA channel to manipulate
1128 * @device: ATA device (numbered from zero) to select
1129 * @wait: non-zero to wait for Status register BSY bit to clear
1130 * @can_sleep: non-zero if context allows sleeping
1132 * Use the method defined in the ATA specification to
1133 * make either device 0, or device 1, active on the
1136 * This is a high-level version of ata_std_dev_select(),
1137 * which additionally provides the services of inserting
1138 * the proper pauses and status polling, where needed.
1144 void ata_dev_select(struct ata_port
*ap
, unsigned int device
,
1145 unsigned int wait
, unsigned int can_sleep
)
1147 if (ata_msg_probe(ap
))
1148 ata_port_printk(ap
, KERN_INFO
, "ata_dev_select: ENTER, "
1149 "device %u, wait %u\n", device
, wait
);
1154 ap
->ops
->dev_select(ap
, device
);
1157 if (can_sleep
&& ap
->link
.device
[device
].class == ATA_DEV_ATAPI
)
1164 * ata_dump_id - IDENTIFY DEVICE info debugging output
1165 * @id: IDENTIFY DEVICE page to dump
1167 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1174 static inline void ata_dump_id(const u16
*id
)
1176 DPRINTK("49==0x%04x "
1186 DPRINTK("80==0x%04x "
1196 DPRINTK("88==0x%04x "
1203 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1204 * @id: IDENTIFY data to compute xfer mask from
1206 * Compute the xfermask for this device. This is not as trivial
1207 * as it seems if we must consider early devices correctly.
1209 * FIXME: pre IDE drive timing (do we care ?).
1217 static unsigned int ata_id_xfermask(const u16
*id
)
1219 unsigned int pio_mask
, mwdma_mask
, udma_mask
;
1221 /* Usual case. Word 53 indicates word 64 is valid */
1222 if (id
[ATA_ID_FIELD_VALID
] & (1 << 1)) {
1223 pio_mask
= id
[ATA_ID_PIO_MODES
] & 0x03;
1227 /* If word 64 isn't valid then Word 51 high byte holds
1228 * the PIO timing number for the maximum. Turn it into
1231 u8 mode
= (id
[ATA_ID_OLD_PIO_MODES
] >> 8) & 0xFF;
1232 if (mode
< 5) /* Valid PIO range */
1233 pio_mask
= (2 << mode
) - 1;
1237 /* But wait.. there's more. Design your standards by
1238 * committee and you too can get a free iordy field to
1239 * process. However its the speeds not the modes that
1240 * are supported... Note drivers using the timing API
1241 * will get this right anyway
1245 mwdma_mask
= id
[ATA_ID_MWDMA_MODES
] & 0x07;
1247 if (ata_id_is_cfa(id
)) {
1249 * Process compact flash extended modes
1251 int pio
= id
[163] & 0x7;
1252 int dma
= (id
[163] >> 3) & 7;
1255 pio_mask
|= (1 << 5);
1257 pio_mask
|= (1 << 6);
1259 mwdma_mask
|= (1 << 3);
1261 mwdma_mask
|= (1 << 4);
1265 if (id
[ATA_ID_FIELD_VALID
] & (1 << 2))
1266 udma_mask
= id
[ATA_ID_UDMA_MODES
] & 0xff;
1268 return ata_pack_xfermask(pio_mask
, mwdma_mask
, udma_mask
);
1272 * ata_port_queue_task - Queue port_task
1273 * @ap: The ata_port to queue port_task for
1274 * @fn: workqueue function to be scheduled
1275 * @data: data for @fn to use
1276 * @delay: delay time for workqueue function
1278 * Schedule @fn(@data) for execution after @delay jiffies using
1279 * port_task. There is one port_task per port and it's the
1280 * user(low level driver)'s responsibility to make sure that only
1281 * one task is active at any given time.
1283 * libata core layer takes care of synchronization between
1284 * port_task and EH. ata_port_queue_task() may be ignored for EH
1288 * Inherited from caller.
1290 void ata_port_queue_task(struct ata_port
*ap
, work_func_t fn
, void *data
,
1291 unsigned long delay
)
1293 PREPARE_DELAYED_WORK(&ap
->port_task
, fn
);
1294 ap
->port_task_data
= data
;
1296 /* may fail if ata_port_flush_task() in progress */
1297 queue_delayed_work(ata_wq
, &ap
->port_task
, delay
);
1301 * ata_port_flush_task - Flush port_task
1302 * @ap: The ata_port to flush port_task for
1304 * After this function completes, port_task is guranteed not to
1305 * be running or scheduled.
1308 * Kernel thread context (may sleep)
1310 void ata_port_flush_task(struct ata_port
*ap
)
1314 cancel_rearming_delayed_work(&ap
->port_task
);
1316 if (ata_msg_ctl(ap
))
1317 ata_port_printk(ap
, KERN_DEBUG
, "%s: EXIT\n", __FUNCTION__
);
1320 static void ata_qc_complete_internal(struct ata_queued_cmd
*qc
)
1322 struct completion
*waiting
= qc
->private_data
;
1328 * ata_exec_internal_sg - execute libata internal command
1329 * @dev: Device to which the command is sent
1330 * @tf: Taskfile registers for the command and the result
1331 * @cdb: CDB for packet command
1332 * @dma_dir: Data tranfer direction of the command
1333 * @sg: sg list for the data buffer of the command
1334 * @n_elem: Number of sg entries
1336 * Executes libata internal command with timeout. @tf contains
1337 * command on entry and result on return. Timeout and error
1338 * conditions are reported via return value. No recovery action
1339 * is taken after a command times out. It's caller's duty to
1340 * clean up after timeout.
1343 * None. Should be called with kernel context, might sleep.
1346 * Zero on success, AC_ERR_* mask on failure
1348 unsigned ata_exec_internal_sg(struct ata_device
*dev
,
1349 struct ata_taskfile
*tf
, const u8
*cdb
,
1350 int dma_dir
, struct scatterlist
*sg
,
1351 unsigned int n_elem
)
1353 struct ata_link
*link
= dev
->link
;
1354 struct ata_port
*ap
= link
->ap
;
1355 u8 command
= tf
->command
;
1356 struct ata_queued_cmd
*qc
;
1357 unsigned int tag
, preempted_tag
;
1358 u32 preempted_sactive
, preempted_qc_active
;
1359 DECLARE_COMPLETION_ONSTACK(wait
);
1360 unsigned long flags
;
1361 unsigned int err_mask
;
1364 spin_lock_irqsave(ap
->lock
, flags
);
1366 /* no internal command while frozen */
1367 if (ap
->pflags
& ATA_PFLAG_FROZEN
) {
1368 spin_unlock_irqrestore(ap
->lock
, flags
);
1369 return AC_ERR_SYSTEM
;
1372 /* initialize internal qc */
1374 /* XXX: Tag 0 is used for drivers with legacy EH as some
1375 * drivers choke if any other tag is given. This breaks
1376 * ata_tag_internal() test for those drivers. Don't use new
1377 * EH stuff without converting to it.
1379 if (ap
->ops
->error_handler
)
1380 tag
= ATA_TAG_INTERNAL
;
1384 if (test_and_set_bit(tag
, &ap
->qc_allocated
))
1386 qc
= __ata_qc_from_tag(ap
, tag
);
1394 preempted_tag
= link
->active_tag
;
1395 preempted_sactive
= link
->sactive
;
1396 preempted_qc_active
= ap
->qc_active
;
1397 link
->active_tag
= ATA_TAG_POISON
;
1401 /* prepare & issue qc */
1404 memcpy(qc
->cdb
, cdb
, ATAPI_CDB_LEN
);
1405 qc
->flags
|= ATA_QCFLAG_RESULT_TF
;
1406 qc
->dma_dir
= dma_dir
;
1407 if (dma_dir
!= DMA_NONE
) {
1408 unsigned int i
, buflen
= 0;
1410 for (i
= 0; i
< n_elem
; i
++)
1411 buflen
+= sg
[i
].length
;
1413 ata_sg_init(qc
, sg
, n_elem
);
1414 qc
->nbytes
= buflen
;
1417 qc
->private_data
= &wait
;
1418 qc
->complete_fn
= ata_qc_complete_internal
;
1422 spin_unlock_irqrestore(ap
->lock
, flags
);
1424 rc
= wait_for_completion_timeout(&wait
, ata_probe_timeout
);
1426 ata_port_flush_task(ap
);
1429 spin_lock_irqsave(ap
->lock
, flags
);
1431 /* We're racing with irq here. If we lose, the
1432 * following test prevents us from completing the qc
1433 * twice. If we win, the port is frozen and will be
1434 * cleaned up by ->post_internal_cmd().
1436 if (qc
->flags
& ATA_QCFLAG_ACTIVE
) {
1437 qc
->err_mask
|= AC_ERR_TIMEOUT
;
1439 if (ap
->ops
->error_handler
)
1440 ata_port_freeze(ap
);
1442 ata_qc_complete(qc
);
1444 if (ata_msg_warn(ap
))
1445 ata_dev_printk(dev
, KERN_WARNING
,
1446 "qc timeout (cmd 0x%x)\n", command
);
1449 spin_unlock_irqrestore(ap
->lock
, flags
);
1452 /* do post_internal_cmd */
1453 if (ap
->ops
->post_internal_cmd
)
1454 ap
->ops
->post_internal_cmd(qc
);
1456 /* perform minimal error analysis */
1457 if (qc
->flags
& ATA_QCFLAG_FAILED
) {
1458 if (qc
->result_tf
.command
& (ATA_ERR
| ATA_DF
))
1459 qc
->err_mask
|= AC_ERR_DEV
;
1462 qc
->err_mask
|= AC_ERR_OTHER
;
1464 if (qc
->err_mask
& ~AC_ERR_OTHER
)
1465 qc
->err_mask
&= ~AC_ERR_OTHER
;
1469 spin_lock_irqsave(ap
->lock
, flags
);
1471 *tf
= qc
->result_tf
;
1472 err_mask
= qc
->err_mask
;
1475 link
->active_tag
= preempted_tag
;
1476 link
->sactive
= preempted_sactive
;
1477 ap
->qc_active
= preempted_qc_active
;
1479 /* XXX - Some LLDDs (sata_mv) disable port on command failure.
1480 * Until those drivers are fixed, we detect the condition
1481 * here, fail the command with AC_ERR_SYSTEM and reenable the
1484 * Note that this doesn't change any behavior as internal
1485 * command failure results in disabling the device in the
1486 * higher layer for LLDDs without new reset/EH callbacks.
1488 * Kill the following code as soon as those drivers are fixed.
1490 if (ap
->flags
& ATA_FLAG_DISABLED
) {
1491 err_mask
|= AC_ERR_SYSTEM
;
1495 spin_unlock_irqrestore(ap
->lock
, flags
);
1501 * ata_exec_internal - execute libata internal command
1502 * @dev: Device to which the command is sent
1503 * @tf: Taskfile registers for the command and the result
1504 * @cdb: CDB for packet command
1505 * @dma_dir: Data tranfer direction of the command
1506 * @buf: Data buffer of the command
1507 * @buflen: Length of data buffer
1509 * Wrapper around ata_exec_internal_sg() which takes simple
1510 * buffer instead of sg list.
1513 * None. Should be called with kernel context, might sleep.
1516 * Zero on success, AC_ERR_* mask on failure
1518 unsigned ata_exec_internal(struct ata_device
*dev
,
1519 struct ata_taskfile
*tf
, const u8
*cdb
,
1520 int dma_dir
, void *buf
, unsigned int buflen
)
1522 struct scatterlist
*psg
= NULL
, sg
;
1523 unsigned int n_elem
= 0;
1525 if (dma_dir
!= DMA_NONE
) {
1527 sg_init_one(&sg
, buf
, buflen
);
1532 return ata_exec_internal_sg(dev
, tf
, cdb
, dma_dir
, psg
, n_elem
);
1536 * ata_do_simple_cmd - execute simple internal command
1537 * @dev: Device to which the command is sent
1538 * @cmd: Opcode to execute
1540 * Execute a 'simple' command, that only consists of the opcode
1541 * 'cmd' itself, without filling any other registers
1544 * Kernel thread context (may sleep).
1547 * Zero on success, AC_ERR_* mask on failure
1549 unsigned int ata_do_simple_cmd(struct ata_device
*dev
, u8 cmd
)
1551 struct ata_taskfile tf
;
1553 ata_tf_init(dev
, &tf
);
1556 tf
.flags
|= ATA_TFLAG_DEVICE
;
1557 tf
.protocol
= ATA_PROT_NODATA
;
1559 return ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
1563 * ata_pio_need_iordy - check if iordy needed
1566 * Check if the current speed of the device requires IORDY. Used
1567 * by various controllers for chip configuration.
1570 unsigned int ata_pio_need_iordy(const struct ata_device
*adev
)
1572 /* Controller doesn't support IORDY. Probably a pointless check
1573 as the caller should know this */
1574 if (adev
->link
->ap
->flags
& ATA_FLAG_NO_IORDY
)
1576 /* PIO3 and higher it is mandatory */
1577 if (adev
->pio_mode
> XFER_PIO_2
)
1579 /* We turn it on when possible */
1580 if (ata_id_has_iordy(adev
->id
))
1586 * ata_pio_mask_no_iordy - Return the non IORDY mask
1589 * Compute the highest mode possible if we are not using iordy. Return
1590 * -1 if no iordy mode is available.
1593 static u32
ata_pio_mask_no_iordy(const struct ata_device
*adev
)
1595 /* If we have no drive specific rule, then PIO 2 is non IORDY */
1596 if (adev
->id
[ATA_ID_FIELD_VALID
] & 2) { /* EIDE */
1597 u16 pio
= adev
->id
[ATA_ID_EIDE_PIO
];
1598 /* Is the speed faster than the drive allows non IORDY ? */
1600 /* This is cycle times not frequency - watch the logic! */
1601 if (pio
> 240) /* PIO2 is 240nS per cycle */
1602 return 3 << ATA_SHIFT_PIO
;
1603 return 7 << ATA_SHIFT_PIO
;
1606 return 3 << ATA_SHIFT_PIO
;
1610 * ata_dev_read_id - Read ID data from the specified device
1611 * @dev: target device
1612 * @p_class: pointer to class of the target device (may be changed)
1613 * @flags: ATA_READID_* flags
1614 * @id: buffer to read IDENTIFY data into
1616 * Read ID data from the specified device. ATA_CMD_ID_ATA is
1617 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
1618 * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS
1619 * for pre-ATA4 drives.
1622 * Kernel thread context (may sleep)
1625 * 0 on success, -errno otherwise.
1627 int ata_dev_read_id(struct ata_device
*dev
, unsigned int *p_class
,
1628 unsigned int flags
, u16
*id
)
1630 struct ata_port
*ap
= dev
->link
->ap
;
1631 unsigned int class = *p_class
;
1632 struct ata_taskfile tf
;
1633 unsigned int err_mask
= 0;
1635 int may_fallback
= 1, tried_spinup
= 0;
1638 if (ata_msg_ctl(ap
))
1639 ata_dev_printk(dev
, KERN_DEBUG
, "%s: ENTER\n", __FUNCTION__
);
1641 ata_dev_select(ap
, dev
->devno
, 1, 1); /* select device 0/1 */
1643 ata_tf_init(dev
, &tf
);
1647 tf
.command
= ATA_CMD_ID_ATA
;
1650 tf
.command
= ATA_CMD_ID_ATAPI
;
1654 reason
= "unsupported class";
1658 tf
.protocol
= ATA_PROT_PIO
;
1660 /* Some devices choke if TF registers contain garbage. Make
1661 * sure those are properly initialized.
1663 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
1665 /* Device presence detection is unreliable on some
1666 * controllers. Always poll IDENTIFY if available.
1668 tf
.flags
|= ATA_TFLAG_POLLING
;
1670 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_FROM_DEVICE
,
1671 id
, sizeof(id
[0]) * ATA_ID_WORDS
);
1673 if (err_mask
& AC_ERR_NODEV_HINT
) {
1674 DPRINTK("ata%u.%d: NODEV after polling detection\n",
1675 ap
->print_id
, dev
->devno
);
1679 /* Device or controller might have reported the wrong
1680 * device class. Give a shot at the other IDENTIFY if
1681 * the current one is aborted by the device.
1684 (err_mask
== AC_ERR_DEV
) && (tf
.feature
& ATA_ABORTED
)) {
1687 if (class == ATA_DEV_ATA
)
1688 class = ATA_DEV_ATAPI
;
1690 class = ATA_DEV_ATA
;
1695 reason
= "I/O error";
1699 /* Falling back doesn't make sense if ID data was read
1700 * successfully at least once.
1704 swap_buf_le16(id
, ATA_ID_WORDS
);
1708 reason
= "device reports invalid type";
1710 if (class == ATA_DEV_ATA
) {
1711 if (!ata_id_is_ata(id
) && !ata_id_is_cfa(id
))
1714 if (ata_id_is_ata(id
))
1718 if (!tried_spinup
&& (id
[2] == 0x37c8 || id
[2] == 0x738c)) {
1721 * Drive powered-up in standby mode, and requires a specific
1722 * SET_FEATURES spin-up subcommand before it will accept
1723 * anything other than the original IDENTIFY command.
1725 ata_tf_init(dev
, &tf
);
1726 tf
.command
= ATA_CMD_SET_FEATURES
;
1727 tf
.feature
= SETFEATURES_SPINUP
;
1728 tf
.protocol
= ATA_PROT_NODATA
;
1729 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
1730 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
1731 if (err_mask
&& id
[2] != 0x738c) {
1733 reason
= "SPINUP failed";
1737 * If the drive initially returned incomplete IDENTIFY info,
1738 * we now must reissue the IDENTIFY command.
1740 if (id
[2] == 0x37c8)
1744 if ((flags
& ATA_READID_POSTRESET
) && class == ATA_DEV_ATA
) {
1746 * The exact sequence expected by certain pre-ATA4 drives is:
1749 * INITIALIZE DEVICE PARAMETERS
1751 * Some drives were very specific about that exact sequence.
1753 if (ata_id_major_version(id
) < 4 || !ata_id_has_lba(id
)) {
1754 err_mask
= ata_dev_init_params(dev
, id
[3], id
[6]);
1757 reason
= "INIT_DEV_PARAMS failed";
1761 /* current CHS translation info (id[53-58]) might be
1762 * changed. reread the identify device info.
1764 flags
&= ~ATA_READID_POSTRESET
;
1774 if (ata_msg_warn(ap
))
1775 ata_dev_printk(dev
, KERN_WARNING
, "failed to IDENTIFY "
1776 "(%s, err_mask=0x%x)\n", reason
, err_mask
);
1780 static inline u8
ata_dev_knobble(struct ata_device
*dev
)
1782 struct ata_port
*ap
= dev
->link
->ap
;
1783 return ((ap
->cbl
== ATA_CBL_SATA
) && (!ata_id_is_sata(dev
->id
)));
1786 static void ata_dev_config_ncq(struct ata_device
*dev
,
1787 char *desc
, size_t desc_sz
)
1789 struct ata_port
*ap
= dev
->link
->ap
;
1790 int hdepth
= 0, ddepth
= ata_id_queue_depth(dev
->id
);
1792 if (!ata_id_has_ncq(dev
->id
)) {
1796 if (dev
->horkage
& ATA_HORKAGE_NONCQ
) {
1797 snprintf(desc
, desc_sz
, "NCQ (not used)");
1800 if (ap
->flags
& ATA_FLAG_NCQ
) {
1801 hdepth
= min(ap
->scsi_host
->can_queue
, ATA_MAX_QUEUE
- 1);
1802 dev
->flags
|= ATA_DFLAG_NCQ
;
1805 if (hdepth
>= ddepth
)
1806 snprintf(desc
, desc_sz
, "NCQ (depth %d)", ddepth
);
1808 snprintf(desc
, desc_sz
, "NCQ (depth %d/%d)", hdepth
, ddepth
);
1812 * ata_dev_configure - Configure the specified ATA/ATAPI device
1813 * @dev: Target device to configure
1815 * Configure @dev according to @dev->id. Generic and low-level
1816 * driver specific fixups are also applied.
1819 * Kernel thread context (may sleep)
1822 * 0 on success, -errno otherwise
1824 int ata_dev_configure(struct ata_device
*dev
)
1826 struct ata_port
*ap
= dev
->link
->ap
;
1827 struct ata_eh_context
*ehc
= &dev
->link
->eh_context
;
1828 int print_info
= ehc
->i
.flags
& ATA_EHI_PRINTINFO
;
1829 const u16
*id
= dev
->id
;
1830 unsigned int xfer_mask
;
1831 char revbuf
[7]; /* XYZ-99\0 */
1832 char fwrevbuf
[ATA_ID_FW_REV_LEN
+1];
1833 char modelbuf
[ATA_ID_PROD_LEN
+1];
1836 if (!ata_dev_enabled(dev
) && ata_msg_info(ap
)) {
1837 ata_dev_printk(dev
, KERN_INFO
, "%s: ENTER/EXIT -- nodev\n",
1842 if (ata_msg_probe(ap
))
1843 ata_dev_printk(dev
, KERN_DEBUG
, "%s: ENTER\n", __FUNCTION__
);
1846 dev
->horkage
|= ata_dev_blacklisted(dev
);
1848 /* let ACPI work its magic */
1849 rc
= ata_acpi_on_devcfg(dev
);
1853 /* print device capabilities */
1854 if (ata_msg_probe(ap
))
1855 ata_dev_printk(dev
, KERN_DEBUG
,
1856 "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x "
1857 "85:%04x 86:%04x 87:%04x 88:%04x\n",
1859 id
[49], id
[82], id
[83], id
[84],
1860 id
[85], id
[86], id
[87], id
[88]);
1862 /* initialize to-be-configured parameters */
1863 dev
->flags
&= ~ATA_DFLAG_CFG_MASK
;
1864 dev
->max_sectors
= 0;
1872 * common ATA, ATAPI feature tests
1875 /* find max transfer mode; for printk only */
1876 xfer_mask
= ata_id_xfermask(id
);
1878 if (ata_msg_probe(ap
))
1881 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
1882 ata_id_c_string(dev
->id
, fwrevbuf
, ATA_ID_FW_REV
,
1885 ata_id_c_string(dev
->id
, modelbuf
, ATA_ID_PROD
,
1888 /* ATA-specific feature tests */
1889 if (dev
->class == ATA_DEV_ATA
) {
1890 if (ata_id_is_cfa(id
)) {
1891 if (id
[162] & 1) /* CPRM may make this media unusable */
1892 ata_dev_printk(dev
, KERN_WARNING
,
1893 "supports DRM functions and may "
1894 "not be fully accessable.\n");
1895 snprintf(revbuf
, 7, "CFA");
1898 snprintf(revbuf
, 7, "ATA-%d", ata_id_major_version(id
));
1900 dev
->n_sectors
= ata_id_n_sectors(id
);
1902 if (dev
->id
[59] & 0x100)
1903 dev
->multi_count
= dev
->id
[59] & 0xff;
1905 if (ata_id_has_lba(id
)) {
1906 const char *lba_desc
;
1910 dev
->flags
|= ATA_DFLAG_LBA
;
1911 if (ata_id_has_lba48(id
)) {
1912 dev
->flags
|= ATA_DFLAG_LBA48
;
1915 if (dev
->n_sectors
>= (1UL << 28) &&
1916 ata_id_has_flush_ext(id
))
1917 dev
->flags
|= ATA_DFLAG_FLUSH_EXT
;
1920 if (!(dev
->horkage
& ATA_HORKAGE_BROKEN_HPA
) &&
1921 ata_id_hpa_enabled(dev
->id
))
1922 dev
->n_sectors
= ata_hpa_resize(dev
);
1925 ata_dev_config_ncq(dev
, ncq_desc
, sizeof(ncq_desc
));
1927 /* print device info to dmesg */
1928 if (ata_msg_drv(ap
) && print_info
) {
1929 ata_dev_printk(dev
, KERN_INFO
,
1930 "%s: %s, %s, max %s\n",
1931 revbuf
, modelbuf
, fwrevbuf
,
1932 ata_mode_string(xfer_mask
));
1933 ata_dev_printk(dev
, KERN_INFO
,
1934 "%Lu sectors, multi %u: %s %s\n",
1935 (unsigned long long)dev
->n_sectors
,
1936 dev
->multi_count
, lba_desc
, ncq_desc
);
1941 /* Default translation */
1942 dev
->cylinders
= id
[1];
1944 dev
->sectors
= id
[6];
1946 if (ata_id_current_chs_valid(id
)) {
1947 /* Current CHS translation is valid. */
1948 dev
->cylinders
= id
[54];
1949 dev
->heads
= id
[55];
1950 dev
->sectors
= id
[56];
1953 /* print device info to dmesg */
1954 if (ata_msg_drv(ap
) && print_info
) {
1955 ata_dev_printk(dev
, KERN_INFO
,
1956 "%s: %s, %s, max %s\n",
1957 revbuf
, modelbuf
, fwrevbuf
,
1958 ata_mode_string(xfer_mask
));
1959 ata_dev_printk(dev
, KERN_INFO
,
1960 "%Lu sectors, multi %u, CHS %u/%u/%u\n",
1961 (unsigned long long)dev
->n_sectors
,
1962 dev
->multi_count
, dev
->cylinders
,
1963 dev
->heads
, dev
->sectors
);
1970 /* ATAPI-specific feature tests */
1971 else if (dev
->class == ATA_DEV_ATAPI
) {
1972 char *cdb_intr_string
= "";
1974 rc
= atapi_cdb_len(id
);
1975 if ((rc
< 12) || (rc
> ATAPI_CDB_LEN
)) {
1976 if (ata_msg_warn(ap
))
1977 ata_dev_printk(dev
, KERN_WARNING
,
1978 "unsupported CDB len\n");
1982 dev
->cdb_len
= (unsigned int) rc
;
1984 if (ata_id_cdb_intr(dev
->id
)) {
1985 dev
->flags
|= ATA_DFLAG_CDB_INTR
;
1986 cdb_intr_string
= ", CDB intr";
1989 /* print device info to dmesg */
1990 if (ata_msg_drv(ap
) && print_info
)
1991 ata_dev_printk(dev
, KERN_INFO
,
1992 "ATAPI: %s, %s, max %s%s\n",
1994 ata_mode_string(xfer_mask
),
1998 /* determine max_sectors */
1999 dev
->max_sectors
= ATA_MAX_SECTORS
;
2000 if (dev
->flags
& ATA_DFLAG_LBA48
)
2001 dev
->max_sectors
= ATA_MAX_SECTORS_LBA48
;
2003 if (dev
->horkage
& ATA_HORKAGE_DIAGNOSTIC
) {
2004 /* Let the user know. We don't want to disallow opens for
2005 rescue purposes, or in case the vendor is just a blithering
2008 ata_dev_printk(dev
, KERN_WARNING
,
2009 "Drive reports diagnostics failure. This may indicate a drive\n");
2010 ata_dev_printk(dev
, KERN_WARNING
,
2011 "fault or invalid emulation. Contact drive vendor for information.\n");
2015 /* limit bridge transfers to udma5, 200 sectors */
2016 if (ata_dev_knobble(dev
)) {
2017 if (ata_msg_drv(ap
) && print_info
)
2018 ata_dev_printk(dev
, KERN_INFO
,
2019 "applying bridge limits\n");
2020 dev
->udma_mask
&= ATA_UDMA5
;
2021 dev
->max_sectors
= ATA_MAX_SECTORS
;
2024 if (dev
->horkage
& ATA_HORKAGE_MAX_SEC_128
)
2025 dev
->max_sectors
= min_t(unsigned int, ATA_MAX_SECTORS_128
,
2028 if (ap
->ops
->dev_config
)
2029 ap
->ops
->dev_config(dev
);
2031 if (ata_msg_probe(ap
))
2032 ata_dev_printk(dev
, KERN_DEBUG
, "%s: EXIT, drv_stat = 0x%x\n",
2033 __FUNCTION__
, ata_chk_status(ap
));
2037 if (ata_msg_probe(ap
))
2038 ata_dev_printk(dev
, KERN_DEBUG
,
2039 "%s: EXIT, err\n", __FUNCTION__
);
2044 * ata_cable_40wire - return 40 wire cable type
2047 * Helper method for drivers which want to hardwire 40 wire cable
2051 int ata_cable_40wire(struct ata_port
*ap
)
2053 return ATA_CBL_PATA40
;
2057 * ata_cable_80wire - return 80 wire cable type
2060 * Helper method for drivers which want to hardwire 80 wire cable
2064 int ata_cable_80wire(struct ata_port
*ap
)
2066 return ATA_CBL_PATA80
;
2070 * ata_cable_unknown - return unknown PATA cable.
2073 * Helper method for drivers which have no PATA cable detection.
2076 int ata_cable_unknown(struct ata_port
*ap
)
2078 return ATA_CBL_PATA_UNK
;
2082 * ata_cable_sata - return SATA cable type
2085 * Helper method for drivers which have SATA cables
2088 int ata_cable_sata(struct ata_port
*ap
)
2090 return ATA_CBL_SATA
;
2094 * ata_bus_probe - Reset and probe ATA bus
2097 * Master ATA bus probing function. Initiates a hardware-dependent
2098 * bus reset, then attempts to identify any devices found on
2102 * PCI/etc. bus probe sem.
2105 * Zero on success, negative errno otherwise.
2108 int ata_bus_probe(struct ata_port
*ap
)
2110 unsigned int classes
[ATA_MAX_DEVICES
];
2111 int tries
[ATA_MAX_DEVICES
];
2113 struct ata_device
*dev
;
2117 ata_link_for_each_dev(dev
, &ap
->link
)
2118 tries
[dev
->devno
] = ATA_PROBE_MAX_TRIES
;
2121 /* reset and determine device classes */
2122 ap
->ops
->phy_reset(ap
);
2124 ata_link_for_each_dev(dev
, &ap
->link
) {
2125 if (!(ap
->flags
& ATA_FLAG_DISABLED
) &&
2126 dev
->class != ATA_DEV_UNKNOWN
)
2127 classes
[dev
->devno
] = dev
->class;
2129 classes
[dev
->devno
] = ATA_DEV_NONE
;
2131 dev
->class = ATA_DEV_UNKNOWN
;
2136 /* after the reset the device state is PIO 0 and the controller
2137 state is undefined. Record the mode */
2139 ata_link_for_each_dev(dev
, &ap
->link
)
2140 dev
->pio_mode
= XFER_PIO_0
;
2142 /* read IDENTIFY page and configure devices. We have to do the identify
2143 specific sequence bass-ackwards so that PDIAG- is released by
2146 ata_link_for_each_dev(dev
, &ap
->link
) {
2147 if (tries
[dev
->devno
])
2148 dev
->class = classes
[dev
->devno
];
2150 if (!ata_dev_enabled(dev
))
2153 rc
= ata_dev_read_id(dev
, &dev
->class, ATA_READID_POSTRESET
,
2159 /* Now ask for the cable type as PDIAG- should have been released */
2160 if (ap
->ops
->cable_detect
)
2161 ap
->cbl
= ap
->ops
->cable_detect(ap
);
2163 /* After the identify sequence we can now set up the devices. We do
2164 this in the normal order so that the user doesn't get confused */
2166 ata_link_for_each_dev(dev
, &ap
->link
) {
2167 if (!ata_dev_enabled(dev
))
2170 ap
->link
.eh_context
.i
.flags
|= ATA_EHI_PRINTINFO
;
2171 rc
= ata_dev_configure(dev
);
2172 ap
->link
.eh_context
.i
.flags
&= ~ATA_EHI_PRINTINFO
;
2177 /* configure transfer mode */
2178 rc
= ata_set_mode(&ap
->link
, &dev
);
2182 ata_link_for_each_dev(dev
, &ap
->link
)
2183 if (ata_dev_enabled(dev
))
2186 /* no device present, disable port */
2187 ata_port_disable(ap
);
2188 ap
->ops
->port_disable(ap
);
2192 tries
[dev
->devno
]--;
2196 /* eeek, something went very wrong, give up */
2197 tries
[dev
->devno
] = 0;
2201 /* give it just one more chance */
2202 tries
[dev
->devno
] = min(tries
[dev
->devno
], 1);
2204 if (tries
[dev
->devno
] == 1) {
2205 /* This is the last chance, better to slow
2206 * down than lose it.
2208 sata_down_spd_limit(&ap
->link
);
2209 ata_down_xfermask_limit(dev
, ATA_DNXFER_PIO
);
2213 if (!tries
[dev
->devno
])
2214 ata_dev_disable(dev
);
2220 * ata_port_probe - Mark port as enabled
2221 * @ap: Port for which we indicate enablement
2223 * Modify @ap data structure such that the system
2224 * thinks that the entire port is enabled.
2226 * LOCKING: host lock, or some other form of
2230 void ata_port_probe(struct ata_port
*ap
)
2232 ap
->flags
&= ~ATA_FLAG_DISABLED
;
2236 * sata_print_link_status - Print SATA link status
2237 * @link: SATA link to printk link status about
2239 * This function prints link speed and status of a SATA link.
2244 void sata_print_link_status(struct ata_link
*link
)
2246 u32 sstatus
, scontrol
, tmp
;
2248 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
))
2250 sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
2252 if (ata_link_online(link
)) {
2253 tmp
= (sstatus
>> 4) & 0xf;
2254 ata_link_printk(link
, KERN_INFO
,
2255 "SATA link up %s (SStatus %X SControl %X)\n",
2256 sata_spd_string(tmp
), sstatus
, scontrol
);
2258 ata_link_printk(link
, KERN_INFO
,
2259 "SATA link down (SStatus %X SControl %X)\n",
2265 * __sata_phy_reset - Wake/reset a low-level SATA PHY
2266 * @ap: SATA port associated with target SATA PHY.
2268 * This function issues commands to standard SATA Sxxx
2269 * PHY registers, to wake up the phy (and device), and
2270 * clear any reset condition.
2273 * PCI/etc. bus probe sem.
2276 void __sata_phy_reset(struct ata_port
*ap
)
2278 struct ata_link
*link
= &ap
->link
;
2279 unsigned long timeout
= jiffies
+ (HZ
* 5);
2282 if (ap
->flags
& ATA_FLAG_SATA_RESET
) {
2283 /* issue phy wake/reset */
2284 sata_scr_write_flush(link
, SCR_CONTROL
, 0x301);
2285 /* Couldn't find anything in SATA I/II specs, but
2286 * AHCI-1.1 10.4.2 says at least 1 ms. */
2289 /* phy wake/clear reset */
2290 sata_scr_write_flush(link
, SCR_CONTROL
, 0x300);
2292 /* wait for phy to become ready, if necessary */
2295 sata_scr_read(link
, SCR_STATUS
, &sstatus
);
2296 if ((sstatus
& 0xf) != 1)
2298 } while (time_before(jiffies
, timeout
));
2300 /* print link status */
2301 sata_print_link_status(link
);
2303 /* TODO: phy layer with polling, timeouts, etc. */
2304 if (!ata_link_offline(link
))
2307 ata_port_disable(ap
);
2309 if (ap
->flags
& ATA_FLAG_DISABLED
)
2312 if (ata_busy_sleep(ap
, ATA_TMOUT_BOOT_QUICK
, ATA_TMOUT_BOOT
)) {
2313 ata_port_disable(ap
);
2317 ap
->cbl
= ATA_CBL_SATA
;
2321 * sata_phy_reset - Reset SATA bus.
2322 * @ap: SATA port associated with target SATA PHY.
2324 * This function resets the SATA bus, and then probes
2325 * the bus for devices.
2328 * PCI/etc. bus probe sem.
2331 void sata_phy_reset(struct ata_port
*ap
)
2333 __sata_phy_reset(ap
);
2334 if (ap
->flags
& ATA_FLAG_DISABLED
)
2340 * ata_dev_pair - return other device on cable
2343 * Obtain the other device on the same cable, or if none is
2344 * present NULL is returned
2347 struct ata_device
*ata_dev_pair(struct ata_device
*adev
)
2349 struct ata_link
*link
= adev
->link
;
2350 struct ata_device
*pair
= &link
->device
[1 - adev
->devno
];
2351 if (!ata_dev_enabled(pair
))
2357 * ata_port_disable - Disable port.
2358 * @ap: Port to be disabled.
2360 * Modify @ap data structure such that the system
2361 * thinks that the entire port is disabled, and should
2362 * never attempt to probe or communicate with devices
2365 * LOCKING: host lock, or some other form of
2369 void ata_port_disable(struct ata_port
*ap
)
2371 ap
->link
.device
[0].class = ATA_DEV_NONE
;
2372 ap
->link
.device
[1].class = ATA_DEV_NONE
;
2373 ap
->flags
|= ATA_FLAG_DISABLED
;
2377 * sata_down_spd_limit - adjust SATA spd limit downward
2378 * @link: Link to adjust SATA spd limit for
2380 * Adjust SATA spd limit of @link downward. Note that this
2381 * function only adjusts the limit. The change must be applied
2382 * using sata_set_spd().
2385 * Inherited from caller.
2388 * 0 on success, negative errno on failure
2390 int sata_down_spd_limit(struct ata_link
*link
)
2392 u32 sstatus
, spd
, mask
;
2395 if (!sata_scr_valid(link
))
2398 /* If SCR can be read, use it to determine the current SPD.
2399 * If not, use cached value in link->sata_spd.
2401 rc
= sata_scr_read(link
, SCR_STATUS
, &sstatus
);
2403 spd
= (sstatus
>> 4) & 0xf;
2405 spd
= link
->sata_spd
;
2407 mask
= link
->sata_spd_limit
;
2411 /* unconditionally mask off the highest bit */
2412 highbit
= fls(mask
) - 1;
2413 mask
&= ~(1 << highbit
);
2415 /* Mask off all speeds higher than or equal to the current
2416 * one. Force 1.5Gbps if current SPD is not available.
2419 mask
&= (1 << (spd
- 1)) - 1;
2423 /* were we already at the bottom? */
2427 link
->sata_spd_limit
= mask
;
2429 ata_link_printk(link
, KERN_WARNING
, "limiting SATA link speed to %s\n",
2430 sata_spd_string(fls(mask
)));
2435 static int __sata_set_spd_needed(struct ata_link
*link
, u32
*scontrol
)
2439 if (link
->sata_spd_limit
== UINT_MAX
)
2442 limit
= fls(link
->sata_spd_limit
);
2444 spd
= (*scontrol
>> 4) & 0xf;
2445 *scontrol
= (*scontrol
& ~0xf0) | ((limit
& 0xf) << 4);
2447 return spd
!= limit
;
2451 * sata_set_spd_needed - is SATA spd configuration needed
2452 * @link: Link in question
2454 * Test whether the spd limit in SControl matches
2455 * @link->sata_spd_limit. This function is used to determine
2456 * whether hardreset is necessary to apply SATA spd
2460 * Inherited from caller.
2463 * 1 if SATA spd configuration is needed, 0 otherwise.
2465 int sata_set_spd_needed(struct ata_link
*link
)
2469 if (sata_scr_read(link
, SCR_CONTROL
, &scontrol
))
2472 return __sata_set_spd_needed(link
, &scontrol
);
2476 * sata_set_spd - set SATA spd according to spd limit
2477 * @link: Link to set SATA spd for
2479 * Set SATA spd of @link according to sata_spd_limit.
2482 * Inherited from caller.
2485 * 0 if spd doesn't need to be changed, 1 if spd has been
2486 * changed. Negative errno if SCR registers are inaccessible.
2488 int sata_set_spd(struct ata_link
*link
)
2493 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
2496 if (!__sata_set_spd_needed(link
, &scontrol
))
2499 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
2506 * This mode timing computation functionality is ported over from
2507 * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik
2510 * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
2511 * These were taken from ATA/ATAPI-6 standard, rev 0a, except
2512 * for UDMA6, which is currently supported only by Maxtor drives.
2514 * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0.
2517 static const struct ata_timing ata_timing
[] = {
2519 { XFER_UDMA_6
, 0, 0, 0, 0, 0, 0, 0, 15 },
2520 { XFER_UDMA_5
, 0, 0, 0, 0, 0, 0, 0, 20 },
2521 { XFER_UDMA_4
, 0, 0, 0, 0, 0, 0, 0, 30 },
2522 { XFER_UDMA_3
, 0, 0, 0, 0, 0, 0, 0, 45 },
2524 { XFER_MW_DMA_4
, 25, 0, 0, 0, 55, 20, 80, 0 },
2525 { XFER_MW_DMA_3
, 25, 0, 0, 0, 65, 25, 100, 0 },
2526 { XFER_UDMA_2
, 0, 0, 0, 0, 0, 0, 0, 60 },
2527 { XFER_UDMA_1
, 0, 0, 0, 0, 0, 0, 0, 80 },
2528 { XFER_UDMA_0
, 0, 0, 0, 0, 0, 0, 0, 120 },
2530 /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
2532 { XFER_MW_DMA_2
, 25, 0, 0, 0, 70, 25, 120, 0 },
2533 { XFER_MW_DMA_1
, 45, 0, 0, 0, 80, 50, 150, 0 },
2534 { XFER_MW_DMA_0
, 60, 0, 0, 0, 215, 215, 480, 0 },
2536 { XFER_SW_DMA_2
, 60, 0, 0, 0, 120, 120, 240, 0 },
2537 { XFER_SW_DMA_1
, 90, 0, 0, 0, 240, 240, 480, 0 },
2538 { XFER_SW_DMA_0
, 120, 0, 0, 0, 480, 480, 960, 0 },
2540 { XFER_PIO_6
, 10, 55, 20, 80, 55, 20, 80, 0 },
2541 { XFER_PIO_5
, 15, 65, 25, 100, 65, 25, 100, 0 },
2542 { XFER_PIO_4
, 25, 70, 25, 120, 70, 25, 120, 0 },
2543 { XFER_PIO_3
, 30, 80, 70, 180, 80, 70, 180, 0 },
2545 { XFER_PIO_2
, 30, 290, 40, 330, 100, 90, 240, 0 },
2546 { XFER_PIO_1
, 50, 290, 93, 383, 125, 100, 383, 0 },
2547 { XFER_PIO_0
, 70, 290, 240, 600, 165, 150, 600, 0 },
2549 /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */
2554 #define ENOUGH(v,unit) (((v)-1)/(unit)+1)
2555 #define EZ(v,unit) ((v)?ENOUGH(v,unit):0)
2557 static void ata_timing_quantize(const struct ata_timing
*t
, struct ata_timing
*q
, int T
, int UT
)
2559 q
->setup
= EZ(t
->setup
* 1000, T
);
2560 q
->act8b
= EZ(t
->act8b
* 1000, T
);
2561 q
->rec8b
= EZ(t
->rec8b
* 1000, T
);
2562 q
->cyc8b
= EZ(t
->cyc8b
* 1000, T
);
2563 q
->active
= EZ(t
->active
* 1000, T
);
2564 q
->recover
= EZ(t
->recover
* 1000, T
);
2565 q
->cycle
= EZ(t
->cycle
* 1000, T
);
2566 q
->udma
= EZ(t
->udma
* 1000, UT
);
2569 void ata_timing_merge(const struct ata_timing
*a
, const struct ata_timing
*b
,
2570 struct ata_timing
*m
, unsigned int what
)
2572 if (what
& ATA_TIMING_SETUP
) m
->setup
= max(a
->setup
, b
->setup
);
2573 if (what
& ATA_TIMING_ACT8B
) m
->act8b
= max(a
->act8b
, b
->act8b
);
2574 if (what
& ATA_TIMING_REC8B
) m
->rec8b
= max(a
->rec8b
, b
->rec8b
);
2575 if (what
& ATA_TIMING_CYC8B
) m
->cyc8b
= max(a
->cyc8b
, b
->cyc8b
);
2576 if (what
& ATA_TIMING_ACTIVE
) m
->active
= max(a
->active
, b
->active
);
2577 if (what
& ATA_TIMING_RECOVER
) m
->recover
= max(a
->recover
, b
->recover
);
2578 if (what
& ATA_TIMING_CYCLE
) m
->cycle
= max(a
->cycle
, b
->cycle
);
2579 if (what
& ATA_TIMING_UDMA
) m
->udma
= max(a
->udma
, b
->udma
);
2582 static const struct ata_timing
* ata_timing_find_mode(unsigned short speed
)
2584 const struct ata_timing
*t
;
2586 for (t
= ata_timing
; t
->mode
!= speed
; t
++)
2587 if (t
->mode
== 0xFF)
2592 int ata_timing_compute(struct ata_device
*adev
, unsigned short speed
,
2593 struct ata_timing
*t
, int T
, int UT
)
2595 const struct ata_timing
*s
;
2596 struct ata_timing p
;
2602 if (!(s
= ata_timing_find_mode(speed
)))
2605 memcpy(t
, s
, sizeof(*s
));
2608 * If the drive is an EIDE drive, it can tell us it needs extended
2609 * PIO/MW_DMA cycle timing.
2612 if (adev
->id
[ATA_ID_FIELD_VALID
] & 2) { /* EIDE drive */
2613 memset(&p
, 0, sizeof(p
));
2614 if(speed
>= XFER_PIO_0
&& speed
<= XFER_SW_DMA_0
) {
2615 if (speed
<= XFER_PIO_2
) p
.cycle
= p
.cyc8b
= adev
->id
[ATA_ID_EIDE_PIO
];
2616 else p
.cycle
= p
.cyc8b
= adev
->id
[ATA_ID_EIDE_PIO_IORDY
];
2617 } else if(speed
>= XFER_MW_DMA_0
&& speed
<= XFER_MW_DMA_2
) {
2618 p
.cycle
= adev
->id
[ATA_ID_EIDE_DMA_MIN
];
2620 ata_timing_merge(&p
, t
, t
, ATA_TIMING_CYCLE
| ATA_TIMING_CYC8B
);
2624 * Convert the timing to bus clock counts.
2627 ata_timing_quantize(t
, t
, T
, UT
);
2630 * Even in DMA/UDMA modes we still use PIO access for IDENTIFY,
2631 * S.M.A.R.T * and some other commands. We have to ensure that the
2632 * DMA cycle timing is slower/equal than the fastest PIO timing.
2635 if (speed
> XFER_PIO_6
) {
2636 ata_timing_compute(adev
, adev
->pio_mode
, &p
, T
, UT
);
2637 ata_timing_merge(&p
, t
, t
, ATA_TIMING_ALL
);
2641 * Lengthen active & recovery time so that cycle time is correct.
2644 if (t
->act8b
+ t
->rec8b
< t
->cyc8b
) {
2645 t
->act8b
+= (t
->cyc8b
- (t
->act8b
+ t
->rec8b
)) / 2;
2646 t
->rec8b
= t
->cyc8b
- t
->act8b
;
2649 if (t
->active
+ t
->recover
< t
->cycle
) {
2650 t
->active
+= (t
->cycle
- (t
->active
+ t
->recover
)) / 2;
2651 t
->recover
= t
->cycle
- t
->active
;
2654 /* In a few cases quantisation may produce enough errors to
2655 leave t->cycle too low for the sum of active and recovery
2656 if so we must correct this */
2657 if (t
->active
+ t
->recover
> t
->cycle
)
2658 t
->cycle
= t
->active
+ t
->recover
;
2664 * ata_down_xfermask_limit - adjust dev xfer masks downward
2665 * @dev: Device to adjust xfer masks
2666 * @sel: ATA_DNXFER_* selector
2668 * Adjust xfer masks of @dev downward. Note that this function
2669 * does not apply the change. Invoking ata_set_mode() afterwards
2670 * will apply the limit.
2673 * Inherited from caller.
2676 * 0 on success, negative errno on failure
2678 int ata_down_xfermask_limit(struct ata_device
*dev
, unsigned int sel
)
2681 unsigned int orig_mask
, xfer_mask
;
2682 unsigned int pio_mask
, mwdma_mask
, udma_mask
;
2685 quiet
= !!(sel
& ATA_DNXFER_QUIET
);
2686 sel
&= ~ATA_DNXFER_QUIET
;
2688 xfer_mask
= orig_mask
= ata_pack_xfermask(dev
->pio_mask
,
2691 ata_unpack_xfermask(xfer_mask
, &pio_mask
, &mwdma_mask
, &udma_mask
);
2694 case ATA_DNXFER_PIO
:
2695 highbit
= fls(pio_mask
) - 1;
2696 pio_mask
&= ~(1 << highbit
);
2699 case ATA_DNXFER_DMA
:
2701 highbit
= fls(udma_mask
) - 1;
2702 udma_mask
&= ~(1 << highbit
);
2705 } else if (mwdma_mask
) {
2706 highbit
= fls(mwdma_mask
) - 1;
2707 mwdma_mask
&= ~(1 << highbit
);
2713 case ATA_DNXFER_40C
:
2714 udma_mask
&= ATA_UDMA_MASK_40C
;
2717 case ATA_DNXFER_FORCE_PIO0
:
2719 case ATA_DNXFER_FORCE_PIO
:
2728 xfer_mask
&= ata_pack_xfermask(pio_mask
, mwdma_mask
, udma_mask
);
2730 if (!(xfer_mask
& ATA_MASK_PIO
) || xfer_mask
== orig_mask
)
2734 if (xfer_mask
& (ATA_MASK_MWDMA
| ATA_MASK_UDMA
))
2735 snprintf(buf
, sizeof(buf
), "%s:%s",
2736 ata_mode_string(xfer_mask
),
2737 ata_mode_string(xfer_mask
& ATA_MASK_PIO
));
2739 snprintf(buf
, sizeof(buf
), "%s",
2740 ata_mode_string(xfer_mask
));
2742 ata_dev_printk(dev
, KERN_WARNING
,
2743 "limiting speed to %s\n", buf
);
2746 ata_unpack_xfermask(xfer_mask
, &dev
->pio_mask
, &dev
->mwdma_mask
,
2752 static int ata_dev_set_mode(struct ata_device
*dev
)
2754 struct ata_eh_context
*ehc
= &dev
->link
->eh_context
;
2755 unsigned int err_mask
;
2758 dev
->flags
&= ~ATA_DFLAG_PIO
;
2759 if (dev
->xfer_shift
== ATA_SHIFT_PIO
)
2760 dev
->flags
|= ATA_DFLAG_PIO
;
2762 err_mask
= ata_dev_set_xfermode(dev
);
2763 /* Old CFA may refuse this command, which is just fine */
2764 if (dev
->xfer_shift
== ATA_SHIFT_PIO
&& ata_id_is_cfa(dev
->id
))
2765 err_mask
&= ~AC_ERR_DEV
;
2766 /* Some very old devices and some bad newer ones fail any kind of
2767 SET_XFERMODE request but support PIO0-2 timings and no IORDY */
2768 if (dev
->xfer_shift
== ATA_SHIFT_PIO
&& !ata_id_has_iordy(dev
->id
) &&
2769 dev
->pio_mode
<= XFER_PIO_2
)
2770 err_mask
&= ~AC_ERR_DEV
;
2772 ata_dev_printk(dev
, KERN_ERR
, "failed to set xfermode "
2773 "(err_mask=0x%x)\n", err_mask
);
2777 ehc
->i
.flags
|= ATA_EHI_POST_SETMODE
;
2778 rc
= ata_dev_revalidate(dev
, 0);
2779 ehc
->i
.flags
&= ~ATA_EHI_POST_SETMODE
;
2783 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
2784 dev
->xfer_shift
, (int)dev
->xfer_mode
);
2786 ata_dev_printk(dev
, KERN_INFO
, "configured for %s\n",
2787 ata_mode_string(ata_xfer_mode2mask(dev
->xfer_mode
)));
2792 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
2793 * @link: link on which timings will be programmed
2794 * @r_failed_dev: out paramter for failed device
2796 * Standard implementation of the function used to tune and set
2797 * ATA device disk transfer mode (PIO3, UDMA6, etc.). If
2798 * ata_dev_set_mode() fails, pointer to the failing device is
2799 * returned in @r_failed_dev.
2802 * PCI/etc. bus probe sem.
2805 * 0 on success, negative errno otherwise
2808 int ata_do_set_mode(struct ata_link
*link
, struct ata_device
**r_failed_dev
)
2810 struct ata_port
*ap
= link
->ap
;
2811 struct ata_device
*dev
;
2812 int rc
= 0, used_dma
= 0, found
= 0;
2814 /* step 1: calculate xfer_mask */
2815 ata_link_for_each_dev(dev
, link
) {
2816 unsigned int pio_mask
, dma_mask
;
2818 if (!ata_dev_enabled(dev
))
2821 ata_dev_xfermask(dev
);
2823 pio_mask
= ata_pack_xfermask(dev
->pio_mask
, 0, 0);
2824 dma_mask
= ata_pack_xfermask(0, dev
->mwdma_mask
, dev
->udma_mask
);
2825 dev
->pio_mode
= ata_xfer_mask2mode(pio_mask
);
2826 dev
->dma_mode
= ata_xfer_mask2mode(dma_mask
);
2835 /* step 2: always set host PIO timings */
2836 ata_link_for_each_dev(dev
, link
) {
2837 if (!ata_dev_enabled(dev
))
2840 if (!dev
->pio_mode
) {
2841 ata_dev_printk(dev
, KERN_WARNING
, "no PIO support\n");
2846 dev
->xfer_mode
= dev
->pio_mode
;
2847 dev
->xfer_shift
= ATA_SHIFT_PIO
;
2848 if (ap
->ops
->set_piomode
)
2849 ap
->ops
->set_piomode(ap
, dev
);
2852 /* step 3: set host DMA timings */
2853 ata_link_for_each_dev(dev
, link
) {
2854 if (!ata_dev_enabled(dev
) || !dev
->dma_mode
)
2857 dev
->xfer_mode
= dev
->dma_mode
;
2858 dev
->xfer_shift
= ata_xfer_mode2shift(dev
->dma_mode
);
2859 if (ap
->ops
->set_dmamode
)
2860 ap
->ops
->set_dmamode(ap
, dev
);
2863 /* step 4: update devices' xfer mode */
2864 ata_link_for_each_dev(dev
, link
) {
2865 /* don't update suspended devices' xfer mode */
2866 if (!ata_dev_enabled(dev
))
2869 rc
= ata_dev_set_mode(dev
);
2874 /* Record simplex status. If we selected DMA then the other
2875 * host channels are not permitted to do so.
2877 if (used_dma
&& (ap
->host
->flags
& ATA_HOST_SIMPLEX
))
2878 ap
->host
->simplex_claimed
= ap
;
2882 *r_failed_dev
= dev
;
2887 * ata_set_mode - Program timings and issue SET FEATURES - XFER
2888 * @link: link on which timings will be programmed
2889 * @r_failed_dev: out paramter for failed device
2891 * Set ATA device disk transfer mode (PIO3, UDMA6, etc.). If
2892 * ata_set_mode() fails, pointer to the failing device is
2893 * returned in @r_failed_dev.
2896 * PCI/etc. bus probe sem.
2899 * 0 on success, negative errno otherwise
2901 int ata_set_mode(struct ata_link
*link
, struct ata_device
**r_failed_dev
)
2903 struct ata_port
*ap
= link
->ap
;
2905 /* has private set_mode? */
2906 if (ap
->ops
->set_mode
)
2907 return ap
->ops
->set_mode(link
, r_failed_dev
);
2908 return ata_do_set_mode(link
, r_failed_dev
);
2912 * ata_tf_to_host - issue ATA taskfile to host controller
2913 * @ap: port to which command is being issued
2914 * @tf: ATA taskfile register set
2916 * Issues ATA taskfile register set to ATA host controller,
2917 * with proper synchronization with interrupt handler and
2921 * spin_lock_irqsave(host lock)
2924 static inline void ata_tf_to_host(struct ata_port
*ap
,
2925 const struct ata_taskfile
*tf
)
2927 ap
->ops
->tf_load(ap
, tf
);
2928 ap
->ops
->exec_command(ap
, tf
);
2932 * ata_busy_sleep - sleep until BSY clears, or timeout
2933 * @ap: port containing status register to be polled
2934 * @tmout_pat: impatience timeout
2935 * @tmout: overall timeout
2937 * Sleep until ATA Status register bit BSY clears,
2938 * or a timeout occurs.
2941 * Kernel thread context (may sleep).
2944 * 0 on success, -errno otherwise.
2946 int ata_busy_sleep(struct ata_port
*ap
,
2947 unsigned long tmout_pat
, unsigned long tmout
)
2949 unsigned long timer_start
, timeout
;
2952 status
= ata_busy_wait(ap
, ATA_BUSY
, 300);
2953 timer_start
= jiffies
;
2954 timeout
= timer_start
+ tmout_pat
;
2955 while (status
!= 0xff && (status
& ATA_BUSY
) &&
2956 time_before(jiffies
, timeout
)) {
2958 status
= ata_busy_wait(ap
, ATA_BUSY
, 3);
2961 if (status
!= 0xff && (status
& ATA_BUSY
))
2962 ata_port_printk(ap
, KERN_WARNING
,
2963 "port is slow to respond, please be patient "
2964 "(Status 0x%x)\n", status
);
2966 timeout
= timer_start
+ tmout
;
2967 while (status
!= 0xff && (status
& ATA_BUSY
) &&
2968 time_before(jiffies
, timeout
)) {
2970 status
= ata_chk_status(ap
);
2976 if (status
& ATA_BUSY
) {
2977 ata_port_printk(ap
, KERN_ERR
, "port failed to respond "
2978 "(%lu secs, Status 0x%x)\n",
2979 tmout
/ HZ
, status
);
2987 * ata_wait_ready - sleep until BSY clears, or timeout
2988 * @ap: port containing status register to be polled
2989 * @deadline: deadline jiffies for the operation
2991 * Sleep until ATA Status register bit BSY clears, or timeout
2995 * Kernel thread context (may sleep).
2998 * 0 on success, -errno otherwise.
3000 int ata_wait_ready(struct ata_port
*ap
, unsigned long deadline
)
3002 unsigned long start
= jiffies
;
3006 u8 status
= ata_chk_status(ap
);
3007 unsigned long now
= jiffies
;
3009 if (!(status
& ATA_BUSY
))
3011 if (!ata_link_online(&ap
->link
) && status
== 0xff)
3013 if (time_after(now
, deadline
))
3016 if (!warned
&& time_after(now
, start
+ 5 * HZ
) &&
3017 (deadline
- now
> 3 * HZ
)) {
3018 ata_port_printk(ap
, KERN_WARNING
,
3019 "port is slow to respond, please be patient "
3020 "(Status 0x%x)\n", status
);
3028 static int ata_bus_post_reset(struct ata_port
*ap
, unsigned int devmask
,
3029 unsigned long deadline
)
3031 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3032 unsigned int dev0
= devmask
& (1 << 0);
3033 unsigned int dev1
= devmask
& (1 << 1);
3036 /* if device 0 was found in ata_devchk, wait for its
3040 rc
= ata_wait_ready(ap
, deadline
);
3048 /* if device 1 was found in ata_devchk, wait for register
3049 * access briefly, then wait for BSY to clear.
3054 ap
->ops
->dev_select(ap
, 1);
3056 /* Wait for register access. Some ATAPI devices fail
3057 * to set nsect/lbal after reset, so don't waste too
3058 * much time on it. We're gonna wait for !BSY anyway.
3060 for (i
= 0; i
< 2; i
++) {
3063 nsect
= ioread8(ioaddr
->nsect_addr
);
3064 lbal
= ioread8(ioaddr
->lbal_addr
);
3065 if ((nsect
== 1) && (lbal
== 1))
3067 msleep(50); /* give drive a breather */
3070 rc
= ata_wait_ready(ap
, deadline
);
3078 /* is all this really necessary? */
3079 ap
->ops
->dev_select(ap
, 0);
3081 ap
->ops
->dev_select(ap
, 1);
3083 ap
->ops
->dev_select(ap
, 0);
3088 static int ata_bus_softreset(struct ata_port
*ap
, unsigned int devmask
,
3089 unsigned long deadline
)
3091 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3093 DPRINTK("ata%u: bus reset via SRST\n", ap
->print_id
);
3095 /* software reset. causes dev0 to be selected */
3096 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3097 udelay(20); /* FIXME: flush */
3098 iowrite8(ap
->ctl
| ATA_SRST
, ioaddr
->ctl_addr
);
3099 udelay(20); /* FIXME: flush */
3100 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3102 /* spec mandates ">= 2ms" before checking status.
3103 * We wait 150ms, because that was the magic delay used for
3104 * ATAPI devices in Hale Landis's ATADRVR, for the period of time
3105 * between when the ATA command register is written, and then
3106 * status is checked. Because waiting for "a while" before
3107 * checking status is fine, post SRST, we perform this magic
3108 * delay here as well.
3110 * Old drivers/ide uses the 2mS rule and then waits for ready
3114 /* Before we perform post reset processing we want to see if
3115 * the bus shows 0xFF because the odd clown forgets the D7
3116 * pulldown resistor.
3118 if (ata_check_status(ap
) == 0xFF)
3121 return ata_bus_post_reset(ap
, devmask
, deadline
);
3125 * ata_bus_reset - reset host port and associated ATA channel
3126 * @ap: port to reset
3128 * This is typically the first time we actually start issuing
3129 * commands to the ATA channel. We wait for BSY to clear, then
3130 * issue EXECUTE DEVICE DIAGNOSTIC command, polling for its
3131 * result. Determine what devices, if any, are on the channel
3132 * by looking at the device 0/1 error register. Look at the signature
3133 * stored in each device's taskfile registers, to determine if
3134 * the device is ATA or ATAPI.
3137 * PCI/etc. bus probe sem.
3138 * Obtains host lock.
3141 * Sets ATA_FLAG_DISABLED if bus reset fails.
3144 void ata_bus_reset(struct ata_port
*ap
)
3146 struct ata_device
*device
= ap
->link
.device
;
3147 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3148 unsigned int slave_possible
= ap
->flags
& ATA_FLAG_SLAVE_POSS
;
3150 unsigned int dev0
, dev1
= 0, devmask
= 0;
3153 DPRINTK("ENTER, host %u, port %u\n", ap
->print_id
, ap
->port_no
);
3155 /* determine if device 0/1 are present */
3156 if (ap
->flags
& ATA_FLAG_SATA_RESET
)
3159 dev0
= ata_devchk(ap
, 0);
3161 dev1
= ata_devchk(ap
, 1);
3165 devmask
|= (1 << 0);
3167 devmask
|= (1 << 1);
3169 /* select device 0 again */
3170 ap
->ops
->dev_select(ap
, 0);
3172 /* issue bus reset */
3173 if (ap
->flags
& ATA_FLAG_SRST
) {
3174 rc
= ata_bus_softreset(ap
, devmask
, jiffies
+ 40 * HZ
);
3175 if (rc
&& rc
!= -ENODEV
)
3180 * determine by signature whether we have ATA or ATAPI devices
3182 device
[0].class = ata_dev_try_classify(ap
, 0, &err
);
3183 if ((slave_possible
) && (err
!= 0x81))
3184 device
[1].class = ata_dev_try_classify(ap
, 1, &err
);
3186 /* is double-select really necessary? */
3187 if (device
[1].class != ATA_DEV_NONE
)
3188 ap
->ops
->dev_select(ap
, 1);
3189 if (device
[0].class != ATA_DEV_NONE
)
3190 ap
->ops
->dev_select(ap
, 0);
3192 /* if no devices were detected, disable this port */
3193 if ((device
[0].class == ATA_DEV_NONE
) &&
3194 (device
[1].class == ATA_DEV_NONE
))
3197 if (ap
->flags
& (ATA_FLAG_SATA_RESET
| ATA_FLAG_SRST
)) {
3198 /* set up device control for ATA_FLAG_SATA_RESET */
3199 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3206 ata_port_printk(ap
, KERN_ERR
, "disabling port\n");
3207 ap
->ops
->port_disable(ap
);
3213 * sata_link_debounce - debounce SATA phy status
3214 * @link: ATA link to debounce SATA phy status for
3215 * @params: timing parameters { interval, duratinon, timeout } in msec
3216 * @deadline: deadline jiffies for the operation
3218 * Make sure SStatus of @link reaches stable state, determined by
3219 * holding the same value where DET is not 1 for @duration polled
3220 * every @interval, before @timeout. Timeout constraints the
3221 * beginning of the stable state. Because DET gets stuck at 1 on
3222 * some controllers after hot unplugging, this functions waits
3223 * until timeout then returns 0 if DET is stable at 1.
3225 * @timeout is further limited by @deadline. The sooner of the
3229 * Kernel thread context (may sleep)
3232 * 0 on success, -errno on failure.
3234 int sata_link_debounce(struct ata_link
*link
, const unsigned long *params
,
3235 unsigned long deadline
)
3237 unsigned long interval_msec
= params
[0];
3238 unsigned long duration
= msecs_to_jiffies(params
[1]);
3239 unsigned long last_jiffies
, t
;
3243 t
= jiffies
+ msecs_to_jiffies(params
[2]);
3244 if (time_before(t
, deadline
))
3247 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
3252 last_jiffies
= jiffies
;
3255 msleep(interval_msec
);
3256 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
3262 if (cur
== 1 && time_before(jiffies
, deadline
))
3264 if (time_after(jiffies
, last_jiffies
+ duration
))
3269 /* unstable, start over */
3271 last_jiffies
= jiffies
;
3273 /* Check deadline. If debouncing failed, return
3274 * -EPIPE to tell upper layer to lower link speed.
3276 if (time_after(jiffies
, deadline
))
3282 * sata_link_resume - resume SATA link
3283 * @link: ATA link to resume SATA
3284 * @params: timing parameters { interval, duratinon, timeout } in msec
3285 * @deadline: deadline jiffies for the operation
3287 * Resume SATA phy @link and debounce it.
3290 * Kernel thread context (may sleep)
3293 * 0 on success, -errno on failure.
3295 int sata_link_resume(struct ata_link
*link
, const unsigned long *params
,
3296 unsigned long deadline
)
3301 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
3304 scontrol
= (scontrol
& 0x0f0) | 0x300;
3306 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
3309 /* Some PHYs react badly if SStatus is pounded immediately
3310 * after resuming. Delay 200ms before debouncing.
3314 return sata_link_debounce(link
, params
, deadline
);
3318 * ata_std_prereset - prepare for reset
3319 * @link: ATA link to be reset
3320 * @deadline: deadline jiffies for the operation
3322 * @link is about to be reset. Initialize it. Failure from
3323 * prereset makes libata abort whole reset sequence and give up
3324 * that port, so prereset should be best-effort. It does its
3325 * best to prepare for reset sequence but if things go wrong, it
3326 * should just whine, not fail.
3329 * Kernel thread context (may sleep)
3332 * 0 on success, -errno otherwise.
3334 int ata_std_prereset(struct ata_link
*link
, unsigned long deadline
)
3336 struct ata_port
*ap
= link
->ap
;
3337 struct ata_eh_context
*ehc
= &link
->eh_context
;
3338 const unsigned long *timing
= sata_ehc_deb_timing(ehc
);
3341 /* handle link resume */
3342 if ((ehc
->i
.flags
& ATA_EHI_RESUME_LINK
) &&
3343 (link
->flags
& ATA_LFLAG_HRST_TO_RESUME
))
3344 ehc
->i
.action
|= ATA_EH_HARDRESET
;
3346 /* if we're about to do hardreset, nothing more to do */
3347 if (ehc
->i
.action
& ATA_EH_HARDRESET
)
3350 /* if SATA, resume link */
3351 if (ap
->flags
& ATA_FLAG_SATA
) {
3352 rc
= sata_link_resume(link
, timing
, deadline
);
3353 /* whine about phy resume failure but proceed */
3354 if (rc
&& rc
!= -EOPNOTSUPP
)
3355 ata_link_printk(link
, KERN_WARNING
, "failed to resume "
3356 "link for reset (errno=%d)\n", rc
);
3359 /* Wait for !BSY if the controller can wait for the first D2H
3360 * Reg FIS and we don't know that no device is attached.
3362 if (!(link
->flags
& ATA_LFLAG_SKIP_D2H_BSY
) && !ata_link_offline(link
)) {
3363 rc
= ata_wait_ready(ap
, deadline
);
3364 if (rc
&& rc
!= -ENODEV
) {
3365 ata_link_printk(link
, KERN_WARNING
, "device not ready "
3366 "(errno=%d), forcing hardreset\n", rc
);
3367 ehc
->i
.action
|= ATA_EH_HARDRESET
;
3375 * ata_std_softreset - reset host port via ATA SRST
3376 * @link: ATA link to reset
3377 * @classes: resulting classes of attached devices
3378 * @deadline: deadline jiffies for the operation
3380 * Reset host port using ATA SRST.
3383 * Kernel thread context (may sleep)
3386 * 0 on success, -errno otherwise.
3388 int ata_std_softreset(struct ata_link
*link
, unsigned int *classes
,
3389 unsigned long deadline
)
3391 struct ata_port
*ap
= link
->ap
;
3392 unsigned int slave_possible
= ap
->flags
& ATA_FLAG_SLAVE_POSS
;
3393 unsigned int devmask
= 0;
3399 if (ata_link_offline(link
)) {
3400 classes
[0] = ATA_DEV_NONE
;
3404 /* determine if device 0/1 are present */
3405 if (ata_devchk(ap
, 0))
3406 devmask
|= (1 << 0);
3407 if (slave_possible
&& ata_devchk(ap
, 1))
3408 devmask
|= (1 << 1);
3410 /* select device 0 again */
3411 ap
->ops
->dev_select(ap
, 0);
3413 /* issue bus reset */
3414 DPRINTK("about to softreset, devmask=%x\n", devmask
);
3415 rc
= ata_bus_softreset(ap
, devmask
, deadline
);
3416 /* if link is occupied, -ENODEV too is an error */
3417 if (rc
&& (rc
!= -ENODEV
|| sata_scr_valid(link
))) {
3418 ata_link_printk(link
, KERN_ERR
, "SRST failed (errno=%d)\n", rc
);
3422 /* determine by signature whether we have ATA or ATAPI devices */
3423 classes
[0] = ata_dev_try_classify(ap
, 0, &err
);
3424 if (slave_possible
&& err
!= 0x81)
3425 classes
[1] = ata_dev_try_classify(ap
, 1, &err
);
3428 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes
[0], classes
[1]);
3433 * sata_link_hardreset - reset link via SATA phy reset
3434 * @link: link to reset
3435 * @timing: timing parameters { interval, duratinon, timeout } in msec
3436 * @deadline: deadline jiffies for the operation
3438 * SATA phy-reset @link using DET bits of SControl register.
3441 * Kernel thread context (may sleep)
3444 * 0 on success, -errno otherwise.
3446 int sata_link_hardreset(struct ata_link
*link
, const unsigned long *timing
,
3447 unsigned long deadline
)
3454 if (sata_set_spd_needed(link
)) {
3455 /* SATA spec says nothing about how to reconfigure
3456 * spd. To be on the safe side, turn off phy during
3457 * reconfiguration. This works for at least ICH7 AHCI
3460 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
3463 scontrol
= (scontrol
& 0x0f0) | 0x304;
3465 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
3471 /* issue phy wake/reset */
3472 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
3475 scontrol
= (scontrol
& 0x0f0) | 0x301;
3477 if ((rc
= sata_scr_write_flush(link
, SCR_CONTROL
, scontrol
)))
3480 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
3481 * 10.4.2 says at least 1 ms.
3485 /* bring link back */
3486 rc
= sata_link_resume(link
, timing
, deadline
);
3488 DPRINTK("EXIT, rc=%d\n", rc
);
3493 * sata_std_hardreset - reset host port via SATA phy reset
3494 * @link: link to reset
3495 * @class: resulting class of attached device
3496 * @deadline: deadline jiffies for the operation
3498 * SATA phy-reset host port using DET bits of SControl register,
3499 * wait for !BSY and classify the attached device.
3502 * Kernel thread context (may sleep)
3505 * 0 on success, -errno otherwise.
3507 int sata_std_hardreset(struct ata_link
*link
, unsigned int *class,
3508 unsigned long deadline
)
3510 struct ata_port
*ap
= link
->ap
;
3511 const unsigned long *timing
= sata_ehc_deb_timing(&link
->eh_context
);
3517 rc
= sata_link_hardreset(link
, timing
, deadline
);
3519 ata_link_printk(link
, KERN_ERR
,
3520 "COMRESET failed (errno=%d)\n", rc
);
3524 /* TODO: phy layer with polling, timeouts, etc. */
3525 if (ata_link_offline(link
)) {
3526 *class = ATA_DEV_NONE
;
3527 DPRINTK("EXIT, link offline\n");
3531 /* wait a while before checking status, see SRST for more info */
3534 rc
= ata_wait_ready(ap
, deadline
);
3535 /* link occupied, -ENODEV too is an error */
3537 ata_link_printk(link
, KERN_ERR
,
3538 "COMRESET failed (errno=%d)\n", rc
);
3542 ap
->ops
->dev_select(ap
, 0); /* probably unnecessary */
3544 *class = ata_dev_try_classify(ap
, 0, NULL
);
3546 DPRINTK("EXIT, class=%u\n", *class);
3551 * ata_std_postreset - standard postreset callback
3552 * @link: the target ata_link
3553 * @classes: classes of attached devices
3555 * This function is invoked after a successful reset. Note that
3556 * the device might have been reset more than once using
3557 * different reset methods before postreset is invoked.
3560 * Kernel thread context (may sleep)
3562 void ata_std_postreset(struct ata_link
*link
, unsigned int *classes
)
3564 struct ata_port
*ap
= link
->ap
;
3569 /* print link status */
3570 sata_print_link_status(link
);
3573 if (sata_scr_read(link
, SCR_ERROR
, &serror
) == 0)
3574 sata_scr_write(link
, SCR_ERROR
, serror
);
3576 /* is double-select really necessary? */
3577 if (classes
[0] != ATA_DEV_NONE
)
3578 ap
->ops
->dev_select(ap
, 1);
3579 if (classes
[1] != ATA_DEV_NONE
)
3580 ap
->ops
->dev_select(ap
, 0);
3582 /* bail out if no device is present */
3583 if (classes
[0] == ATA_DEV_NONE
&& classes
[1] == ATA_DEV_NONE
) {
3584 DPRINTK("EXIT, no device\n");
3588 /* set up device control */
3589 if (ap
->ioaddr
.ctl_addr
)
3590 iowrite8(ap
->ctl
, ap
->ioaddr
.ctl_addr
);
3596 * ata_dev_same_device - Determine whether new ID matches configured device
3597 * @dev: device to compare against
3598 * @new_class: class of the new device
3599 * @new_id: IDENTIFY page of the new device
3601 * Compare @new_class and @new_id against @dev and determine
3602 * whether @dev is the device indicated by @new_class and
3609 * 1 if @dev matches @new_class and @new_id, 0 otherwise.
3611 static int ata_dev_same_device(struct ata_device
*dev
, unsigned int new_class
,
3614 const u16
*old_id
= dev
->id
;
3615 unsigned char model
[2][ATA_ID_PROD_LEN
+ 1];
3616 unsigned char serial
[2][ATA_ID_SERNO_LEN
+ 1];
3618 if (dev
->class != new_class
) {
3619 ata_dev_printk(dev
, KERN_INFO
, "class mismatch %d != %d\n",
3620 dev
->class, new_class
);
3624 ata_id_c_string(old_id
, model
[0], ATA_ID_PROD
, sizeof(model
[0]));
3625 ata_id_c_string(new_id
, model
[1], ATA_ID_PROD
, sizeof(model
[1]));
3626 ata_id_c_string(old_id
, serial
[0], ATA_ID_SERNO
, sizeof(serial
[0]));
3627 ata_id_c_string(new_id
, serial
[1], ATA_ID_SERNO
, sizeof(serial
[1]));
3629 if (strcmp(model
[0], model
[1])) {
3630 ata_dev_printk(dev
, KERN_INFO
, "model number mismatch "
3631 "'%s' != '%s'\n", model
[0], model
[1]);
3635 if (strcmp(serial
[0], serial
[1])) {
3636 ata_dev_printk(dev
, KERN_INFO
, "serial number mismatch "
3637 "'%s' != '%s'\n", serial
[0], serial
[1]);
3645 * ata_dev_reread_id - Re-read IDENTIFY data
3646 * @dev: target ATA device
3647 * @readid_flags: read ID flags
3649 * Re-read IDENTIFY page and make sure @dev is still attached to
3653 * Kernel thread context (may sleep)
3656 * 0 on success, negative errno otherwise
3658 int ata_dev_reread_id(struct ata_device
*dev
, unsigned int readid_flags
)
3660 unsigned int class = dev
->class;
3661 u16
*id
= (void *)dev
->link
->ap
->sector_buf
;
3665 rc
= ata_dev_read_id(dev
, &class, readid_flags
, id
);
3669 /* is the device still there? */
3670 if (!ata_dev_same_device(dev
, class, id
))
3673 memcpy(dev
->id
, id
, sizeof(id
[0]) * ATA_ID_WORDS
);
3678 * ata_dev_revalidate - Revalidate ATA device
3679 * @dev: device to revalidate
3680 * @readid_flags: read ID flags
3682 * Re-read IDENTIFY page, make sure @dev is still attached to the
3683 * port and reconfigure it according to the new IDENTIFY page.
3686 * Kernel thread context (may sleep)
3689 * 0 on success, negative errno otherwise
3691 int ata_dev_revalidate(struct ata_device
*dev
, unsigned int readid_flags
)
3693 u64 n_sectors
= dev
->n_sectors
;
3696 if (!ata_dev_enabled(dev
))
3700 rc
= ata_dev_reread_id(dev
, readid_flags
);
3704 /* configure device according to the new ID */
3705 rc
= ata_dev_configure(dev
);
3709 /* verify n_sectors hasn't changed */
3710 if (dev
->class == ATA_DEV_ATA
&& n_sectors
&&
3711 dev
->n_sectors
!= n_sectors
) {
3712 ata_dev_printk(dev
, KERN_INFO
, "n_sectors mismatch "
3714 (unsigned long long)n_sectors
,
3715 (unsigned long long)dev
->n_sectors
);
3717 /* restore original n_sectors */
3718 dev
->n_sectors
= n_sectors
;
3727 ata_dev_printk(dev
, KERN_ERR
, "revalidation failed (errno=%d)\n", rc
);
3731 struct ata_blacklist_entry
{
3732 const char *model_num
;
3733 const char *model_rev
;
3734 unsigned long horkage
;
3737 static const struct ata_blacklist_entry ata_device_blacklist
[] = {
3738 /* Devices with DMA related problems under Linux */
3739 { "WDC AC11000H", NULL
, ATA_HORKAGE_NODMA
},
3740 { "WDC AC22100H", NULL
, ATA_HORKAGE_NODMA
},
3741 { "WDC AC32500H", NULL
, ATA_HORKAGE_NODMA
},
3742 { "WDC AC33100H", NULL
, ATA_HORKAGE_NODMA
},
3743 { "WDC AC31600H", NULL
, ATA_HORKAGE_NODMA
},
3744 { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA
},
3745 { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA
},
3746 { "Compaq CRD-8241B", NULL
, ATA_HORKAGE_NODMA
},
3747 { "CRD-8400B", NULL
, ATA_HORKAGE_NODMA
},
3748 { "CRD-8480B", NULL
, ATA_HORKAGE_NODMA
},
3749 { "CRD-8482B", NULL
, ATA_HORKAGE_NODMA
},
3750 { "CRD-84", NULL
, ATA_HORKAGE_NODMA
},
3751 { "SanDisk SDP3B", NULL
, ATA_HORKAGE_NODMA
},
3752 { "SanDisk SDP3B-64", NULL
, ATA_HORKAGE_NODMA
},
3753 { "SANYO CD-ROM CRD", NULL
, ATA_HORKAGE_NODMA
},
3754 { "HITACHI CDR-8", NULL
, ATA_HORKAGE_NODMA
},
3755 { "HITACHI CDR-8335", NULL
, ATA_HORKAGE_NODMA
},
3756 { "HITACHI CDR-8435", NULL
, ATA_HORKAGE_NODMA
},
3757 { "Toshiba CD-ROM XM-6202B", NULL
, ATA_HORKAGE_NODMA
},
3758 { "TOSHIBA CD-ROM XM-1702BC", NULL
, ATA_HORKAGE_NODMA
},
3759 { "CD-532E-A", NULL
, ATA_HORKAGE_NODMA
},
3760 { "E-IDE CD-ROM CR-840",NULL
, ATA_HORKAGE_NODMA
},
3761 { "CD-ROM Drive/F5A", NULL
, ATA_HORKAGE_NODMA
},
3762 { "WPI CDD-820", NULL
, ATA_HORKAGE_NODMA
},
3763 { "SAMSUNG CD-ROM SC-148C", NULL
, ATA_HORKAGE_NODMA
},
3764 { "SAMSUNG CD-ROM SC", NULL
, ATA_HORKAGE_NODMA
},
3765 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL
,ATA_HORKAGE_NODMA
},
3766 { "_NEC DV5800A", NULL
, ATA_HORKAGE_NODMA
},
3767 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA
},
3768 { "Seagate STT20000A", NULL
, ATA_HORKAGE_NODMA
},
3769 { "IOMEGA ZIP 250 ATAPI", NULL
, ATA_HORKAGE_NODMA
}, /* temporary fix */
3770 { "IOMEGA ZIP 250 ATAPI Floppy",
3771 NULL
, ATA_HORKAGE_NODMA
},
3773 /* Weird ATAPI devices */
3774 { "TORiSAN DVD-ROM DRD-N216", NULL
, ATA_HORKAGE_MAX_SEC_128
},
3776 /* Devices we expect to fail diagnostics */
3778 /* Devices where NCQ should be avoided */
3780 { "WDC WD740ADFD-00", NULL
, ATA_HORKAGE_NONCQ
},
3781 /* http://thread.gmane.org/gmane.linux.ide/14907 */
3782 { "FUJITSU MHT2060BH", NULL
, ATA_HORKAGE_NONCQ
},
3784 { "Maxtor 6L250S0", "BANC1G10", ATA_HORKAGE_NONCQ
},
3785 { "Maxtor 6B200M0", "BANC1BM0", ATA_HORKAGE_NONCQ
},
3786 { "Maxtor 6B200M0", "BANC1B10", ATA_HORKAGE_NONCQ
},
3787 { "Maxtor 7B250S0", "BANC1B70", ATA_HORKAGE_NONCQ
, },
3788 { "Maxtor 7B300S0", "BANC1B70", ATA_HORKAGE_NONCQ
},
3789 { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ
},
3790 { "HITACHI HDS7250SASUN500G 0621KTAWSD", "K2AOAJ0AHITACHI",
3791 ATA_HORKAGE_NONCQ
},
3792 /* NCQ hard hangs device under heavier load, needs hard power cycle */
3793 { "Maxtor 6B250S0", "BANC1B70", ATA_HORKAGE_NONCQ
},
3794 /* Blacklist entries taken from Silicon Image 3124/3132
3795 Windows driver .inf file - also several Linux problem reports */
3796 { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ
, },
3797 { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ
, },
3798 { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ
, },
3799 /* Drives which do spurious command completion */
3800 { "HTS541680J9SA00", "SB2IC7EP", ATA_HORKAGE_NONCQ
, },
3801 { "HTS541612J9SA00", "SBDIC7JP", ATA_HORKAGE_NONCQ
, },
3802 { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ
, },
3803 { "WDC WD740ADFD-00NLR1", NULL
, ATA_HORKAGE_NONCQ
, },
3804 { "FUJITSU MHV2080BH", "00840028", ATA_HORKAGE_NONCQ
, },
3805 { "ST9160821AS", "3.CLF", ATA_HORKAGE_NONCQ
, },
3806 { "ST3160812AS", "3.AD", ATA_HORKAGE_NONCQ
, },
3807 { "SAMSUNG HD401LJ", "ZZ100-15", ATA_HORKAGE_NONCQ
, },
3809 /* devices which puke on READ_NATIVE_MAX */
3810 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA
, },
3811 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA
},
3812 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA
},
3813 { "MAXTOR 6L080L4", "A93.0500", ATA_HORKAGE_BROKEN_HPA
},
3819 static unsigned long ata_dev_blacklisted(const struct ata_device
*dev
)
3821 unsigned char model_num
[ATA_ID_PROD_LEN
+ 1];
3822 unsigned char model_rev
[ATA_ID_FW_REV_LEN
+ 1];
3823 const struct ata_blacklist_entry
*ad
= ata_device_blacklist
;
3825 ata_id_c_string(dev
->id
, model_num
, ATA_ID_PROD
, sizeof(model_num
));
3826 ata_id_c_string(dev
->id
, model_rev
, ATA_ID_FW_REV
, sizeof(model_rev
));
3828 while (ad
->model_num
) {
3829 if (!strcmp(ad
->model_num
, model_num
)) {
3830 if (ad
->model_rev
== NULL
)
3832 if (!strcmp(ad
->model_rev
, model_rev
))
3840 static int ata_dma_blacklisted(const struct ata_device
*dev
)
3842 /* We don't support polling DMA.
3843 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO)
3844 * if the LLDD handles only interrupts in the HSM_ST_LAST state.
3846 if ((dev
->link
->ap
->flags
& ATA_FLAG_PIO_POLLING
) &&
3847 (dev
->flags
& ATA_DFLAG_CDB_INTR
))
3849 return (dev
->horkage
& ATA_HORKAGE_NODMA
) ? 1 : 0;
3853 * ata_dev_xfermask - Compute supported xfermask of the given device
3854 * @dev: Device to compute xfermask for
3856 * Compute supported xfermask of @dev and store it in
3857 * dev->*_mask. This function is responsible for applying all
3858 * known limits including host controller limits, device
3864 static void ata_dev_xfermask(struct ata_device
*dev
)
3866 struct ata_link
*link
= dev
->link
;
3867 struct ata_port
*ap
= link
->ap
;
3868 struct ata_host
*host
= ap
->host
;
3869 unsigned long xfer_mask
;
3871 /* controller modes available */
3872 xfer_mask
= ata_pack_xfermask(ap
->pio_mask
,
3873 ap
->mwdma_mask
, ap
->udma_mask
);
3875 /* drive modes available */
3876 xfer_mask
&= ata_pack_xfermask(dev
->pio_mask
,
3877 dev
->mwdma_mask
, dev
->udma_mask
);
3878 xfer_mask
&= ata_id_xfermask(dev
->id
);
3881 * CFA Advanced TrueIDE timings are not allowed on a shared
3884 if (ata_dev_pair(dev
)) {
3885 /* No PIO5 or PIO6 */
3886 xfer_mask
&= ~(0x03 << (ATA_SHIFT_PIO
+ 5));
3887 /* No MWDMA3 or MWDMA 4 */
3888 xfer_mask
&= ~(0x03 << (ATA_SHIFT_MWDMA
+ 3));
3891 if (ata_dma_blacklisted(dev
)) {
3892 xfer_mask
&= ~(ATA_MASK_MWDMA
| ATA_MASK_UDMA
);
3893 ata_dev_printk(dev
, KERN_WARNING
,
3894 "device is on DMA blacklist, disabling DMA\n");
3897 if ((host
->flags
& ATA_HOST_SIMPLEX
) &&
3898 host
->simplex_claimed
&& host
->simplex_claimed
!= ap
) {
3899 xfer_mask
&= ~(ATA_MASK_MWDMA
| ATA_MASK_UDMA
);
3900 ata_dev_printk(dev
, KERN_WARNING
, "simplex DMA is claimed by "
3901 "other device, disabling DMA\n");
3904 if (ap
->flags
& ATA_FLAG_NO_IORDY
)
3905 xfer_mask
&= ata_pio_mask_no_iordy(dev
);
3907 if (ap
->ops
->mode_filter
)
3908 xfer_mask
= ap
->ops
->mode_filter(dev
, xfer_mask
);
3910 /* Apply cable rule here. Don't apply it early because when
3911 * we handle hot plug the cable type can itself change.
3912 * Check this last so that we know if the transfer rate was
3913 * solely limited by the cable.
3914 * Unknown or 80 wire cables reported host side are checked
3915 * drive side as well. Cases where we know a 40wire cable
3916 * is used safely for 80 are not checked here.
3918 if (xfer_mask
& (0xF8 << ATA_SHIFT_UDMA
))
3919 /* UDMA/44 or higher would be available */
3920 if((ap
->cbl
== ATA_CBL_PATA40
) ||
3921 (ata_drive_40wire(dev
->id
) &&
3922 (ap
->cbl
== ATA_CBL_PATA_UNK
||
3923 ap
->cbl
== ATA_CBL_PATA80
))) {
3924 ata_dev_printk(dev
, KERN_WARNING
,
3925 "limited to UDMA/33 due to 40-wire cable\n");
3926 xfer_mask
&= ~(0xF8 << ATA_SHIFT_UDMA
);
3929 ata_unpack_xfermask(xfer_mask
, &dev
->pio_mask
,
3930 &dev
->mwdma_mask
, &dev
->udma_mask
);
3934 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
3935 * @dev: Device to which command will be sent
3937 * Issue SET FEATURES - XFER MODE command to device @dev
3941 * PCI/etc. bus probe sem.
3944 * 0 on success, AC_ERR_* mask otherwise.
3947 static unsigned int ata_dev_set_xfermode(struct ata_device
*dev
)
3949 struct ata_taskfile tf
;
3950 unsigned int err_mask
;
3952 /* set up set-features taskfile */
3953 DPRINTK("set features - xfer mode\n");
3955 /* Some controllers and ATAPI devices show flaky interrupt
3956 * behavior after setting xfer mode. Use polling instead.
3958 ata_tf_init(dev
, &tf
);
3959 tf
.command
= ATA_CMD_SET_FEATURES
;
3960 tf
.feature
= SETFEATURES_XFER
;
3961 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
| ATA_TFLAG_POLLING
;
3962 tf
.protocol
= ATA_PROT_NODATA
;
3963 tf
.nsect
= dev
->xfer_mode
;
3965 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
3967 DPRINTK("EXIT, err_mask=%x\n", err_mask
);
3972 * ata_dev_init_params - Issue INIT DEV PARAMS command
3973 * @dev: Device to which command will be sent
3974 * @heads: Number of heads (taskfile parameter)
3975 * @sectors: Number of sectors (taskfile parameter)
3978 * Kernel thread context (may sleep)
3981 * 0 on success, AC_ERR_* mask otherwise.
3983 static unsigned int ata_dev_init_params(struct ata_device
*dev
,
3984 u16 heads
, u16 sectors
)
3986 struct ata_taskfile tf
;
3987 unsigned int err_mask
;
3989 /* Number of sectors per track 1-255. Number of heads 1-16 */
3990 if (sectors
< 1 || sectors
> 255 || heads
< 1 || heads
> 16)
3991 return AC_ERR_INVALID
;
3993 /* set up init dev params taskfile */
3994 DPRINTK("init dev params \n");
3996 ata_tf_init(dev
, &tf
);
3997 tf
.command
= ATA_CMD_INIT_DEV_PARAMS
;
3998 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
3999 tf
.protocol
= ATA_PROT_NODATA
;
4001 tf
.device
|= (heads
- 1) & 0x0f; /* max head = num. of heads - 1 */
4003 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0);
4004 /* A clean abort indicates an original or just out of spec drive
4005 and we should continue as we issue the setup based on the
4006 drive reported working geometry */
4007 if (err_mask
== AC_ERR_DEV
&& (tf
.feature
& ATA_ABORTED
))
4010 DPRINTK("EXIT, err_mask=%x\n", err_mask
);
4015 * ata_sg_clean - Unmap DMA memory associated with command
4016 * @qc: Command containing DMA memory to be released
4018 * Unmap all mapped DMA memory associated with this command.
4021 * spin_lock_irqsave(host lock)
4023 void ata_sg_clean(struct ata_queued_cmd
*qc
)
4025 struct ata_port
*ap
= qc
->ap
;
4026 struct scatterlist
*sg
= qc
->__sg
;
4027 int dir
= qc
->dma_dir
;
4028 void *pad_buf
= NULL
;
4030 WARN_ON(!(qc
->flags
& ATA_QCFLAG_DMAMAP
));
4031 WARN_ON(sg
== NULL
);
4033 if (qc
->flags
& ATA_QCFLAG_SINGLE
)
4034 WARN_ON(qc
->n_elem
> 1);
4036 VPRINTK("unmapping %u sg elements\n", qc
->n_elem
);
4038 /* if we padded the buffer out to 32-bit bound, and data
4039 * xfer direction is from-device, we must copy from the
4040 * pad buffer back into the supplied buffer
4042 if (qc
->pad_len
&& !(qc
->tf
.flags
& ATA_TFLAG_WRITE
))
4043 pad_buf
= ap
->pad
+ (qc
->tag
* ATA_DMA_PAD_SZ
);
4045 if (qc
->flags
& ATA_QCFLAG_SG
) {
4047 dma_unmap_sg(ap
->dev
, sg
, qc
->n_elem
, dir
);
4048 /* restore last sg */
4049 sg
[qc
->orig_n_elem
- 1].length
+= qc
->pad_len
;
4051 struct scatterlist
*psg
= &qc
->pad_sgent
;
4052 void *addr
= kmap_atomic(psg
->page
, KM_IRQ0
);
4053 memcpy(addr
+ psg
->offset
, pad_buf
, qc
->pad_len
);
4054 kunmap_atomic(addr
, KM_IRQ0
);
4058 dma_unmap_single(ap
->dev
,
4059 sg_dma_address(&sg
[0]), sg_dma_len(&sg
[0]),
4062 sg
->length
+= qc
->pad_len
;
4064 memcpy(qc
->buf_virt
+ sg
->length
- qc
->pad_len
,
4065 pad_buf
, qc
->pad_len
);
4068 qc
->flags
&= ~ATA_QCFLAG_DMAMAP
;
4073 * ata_fill_sg - Fill PCI IDE PRD table
4074 * @qc: Metadata associated with taskfile to be transferred
4076 * Fill PCI IDE PRD (scatter-gather) table with segments
4077 * associated with the current disk command.
4080 * spin_lock_irqsave(host lock)
4083 static void ata_fill_sg(struct ata_queued_cmd
*qc
)
4085 struct ata_port
*ap
= qc
->ap
;
4086 struct scatterlist
*sg
;
4089 WARN_ON(qc
->__sg
== NULL
);
4090 WARN_ON(qc
->n_elem
== 0 && qc
->pad_len
== 0);
4093 ata_for_each_sg(sg
, qc
) {
4097 /* determine if physical DMA addr spans 64K boundary.
4098 * Note h/w doesn't support 64-bit, so we unconditionally
4099 * truncate dma_addr_t to u32.
4101 addr
= (u32
) sg_dma_address(sg
);
4102 sg_len
= sg_dma_len(sg
);
4105 offset
= addr
& 0xffff;
4107 if ((offset
+ sg_len
) > 0x10000)
4108 len
= 0x10000 - offset
;
4110 ap
->prd
[idx
].addr
= cpu_to_le32(addr
);
4111 ap
->prd
[idx
].flags_len
= cpu_to_le32(len
& 0xffff);
4112 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx
, addr
, len
);
4121 ap
->prd
[idx
- 1].flags_len
|= cpu_to_le32(ATA_PRD_EOT
);
4125 * ata_fill_sg_dumb - Fill PCI IDE PRD table
4126 * @qc: Metadata associated with taskfile to be transferred
4128 * Fill PCI IDE PRD (scatter-gather) table with segments
4129 * associated with the current disk command. Perform the fill
4130 * so that we avoid writing any length 64K records for
4131 * controllers that don't follow the spec.
4134 * spin_lock_irqsave(host lock)
4137 static void ata_fill_sg_dumb(struct ata_queued_cmd
*qc
)
4139 struct ata_port
*ap
= qc
->ap
;
4140 struct scatterlist
*sg
;
4143 WARN_ON(qc
->__sg
== NULL
);
4144 WARN_ON(qc
->n_elem
== 0 && qc
->pad_len
== 0);
4147 ata_for_each_sg(sg
, qc
) {
4149 u32 sg_len
, len
, blen
;
4151 /* determine if physical DMA addr spans 64K boundary.
4152 * Note h/w doesn't support 64-bit, so we unconditionally
4153 * truncate dma_addr_t to u32.
4155 addr
= (u32
) sg_dma_address(sg
);
4156 sg_len
= sg_dma_len(sg
);
4159 offset
= addr
& 0xffff;
4161 if ((offset
+ sg_len
) > 0x10000)
4162 len
= 0x10000 - offset
;
4164 blen
= len
& 0xffff;
4165 ap
->prd
[idx
].addr
= cpu_to_le32(addr
);
4167 /* Some PATA chipsets like the CS5530 can't
4168 cope with 0x0000 meaning 64K as the spec says */
4169 ap
->prd
[idx
].flags_len
= cpu_to_le32(0x8000);
4171 ap
->prd
[++idx
].addr
= cpu_to_le32(addr
+ 0x8000);
4173 ap
->prd
[idx
].flags_len
= cpu_to_le32(blen
);
4174 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx
, addr
, len
);
4183 ap
->prd
[idx
- 1].flags_len
|= cpu_to_le32(ATA_PRD_EOT
);
4187 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported
4188 * @qc: Metadata associated with taskfile to check
4190 * Allow low-level driver to filter ATA PACKET commands, returning
4191 * a status indicating whether or not it is OK to use DMA for the
4192 * supplied PACKET command.
4195 * spin_lock_irqsave(host lock)
4197 * RETURNS: 0 when ATAPI DMA can be used
4200 int ata_check_atapi_dma(struct ata_queued_cmd
*qc
)
4202 struct ata_port
*ap
= qc
->ap
;
4204 /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a
4205 * few ATAPI devices choke on such DMA requests.
4207 if (unlikely(qc
->nbytes
& 15))
4210 if (ap
->ops
->check_atapi_dma
)
4211 return ap
->ops
->check_atapi_dma(qc
);
4217 * ata_qc_prep - Prepare taskfile for submission
4218 * @qc: Metadata associated with taskfile to be prepared
4220 * Prepare ATA taskfile for submission.
4223 * spin_lock_irqsave(host lock)
4225 void ata_qc_prep(struct ata_queued_cmd
*qc
)
4227 if (!(qc
->flags
& ATA_QCFLAG_DMAMAP
))
4234 * ata_dumb_qc_prep - Prepare taskfile for submission
4235 * @qc: Metadata associated with taskfile to be prepared
4237 * Prepare ATA taskfile for submission.
4240 * spin_lock_irqsave(host lock)
4242 void ata_dumb_qc_prep(struct ata_queued_cmd
*qc
)
4244 if (!(qc
->flags
& ATA_QCFLAG_DMAMAP
))
4247 ata_fill_sg_dumb(qc
);
4250 void ata_noop_qc_prep(struct ata_queued_cmd
*qc
) { }
4253 * ata_sg_init_one - Associate command with memory buffer
4254 * @qc: Command to be associated
4255 * @buf: Memory buffer
4256 * @buflen: Length of memory buffer, in bytes.
4258 * Initialize the data-related elements of queued_cmd @qc
4259 * to point to a single memory buffer, @buf of byte length @buflen.
4262 * spin_lock_irqsave(host lock)
4265 void ata_sg_init_one(struct ata_queued_cmd
*qc
, void *buf
, unsigned int buflen
)
4267 qc
->flags
|= ATA_QCFLAG_SINGLE
;
4269 qc
->__sg
= &qc
->sgent
;
4271 qc
->orig_n_elem
= 1;
4273 qc
->nbytes
= buflen
;
4275 sg_init_one(&qc
->sgent
, buf
, buflen
);
4279 * ata_sg_init - Associate command with scatter-gather table.
4280 * @qc: Command to be associated
4281 * @sg: Scatter-gather table.
4282 * @n_elem: Number of elements in s/g table.
4284 * Initialize the data-related elements of queued_cmd @qc
4285 * to point to a scatter-gather table @sg, containing @n_elem
4289 * spin_lock_irqsave(host lock)
4292 void ata_sg_init(struct ata_queued_cmd
*qc
, struct scatterlist
*sg
,
4293 unsigned int n_elem
)
4295 qc
->flags
|= ATA_QCFLAG_SG
;
4297 qc
->n_elem
= n_elem
;
4298 qc
->orig_n_elem
= n_elem
;
4302 * ata_sg_setup_one - DMA-map the memory buffer associated with a command.
4303 * @qc: Command with memory buffer to be mapped.
4305 * DMA-map the memory buffer associated with queued_cmd @qc.
4308 * spin_lock_irqsave(host lock)
4311 * Zero on success, negative on error.
4314 static int ata_sg_setup_one(struct ata_queued_cmd
*qc
)
4316 struct ata_port
*ap
= qc
->ap
;
4317 int dir
= qc
->dma_dir
;
4318 struct scatterlist
*sg
= qc
->__sg
;
4319 dma_addr_t dma_address
;
4322 /* we must lengthen transfers to end on a 32-bit boundary */
4323 qc
->pad_len
= sg
->length
& 3;
4325 void *pad_buf
= ap
->pad
+ (qc
->tag
* ATA_DMA_PAD_SZ
);
4326 struct scatterlist
*psg
= &qc
->pad_sgent
;
4328 WARN_ON(qc
->dev
->class != ATA_DEV_ATAPI
);
4330 memset(pad_buf
, 0, ATA_DMA_PAD_SZ
);
4332 if (qc
->tf
.flags
& ATA_TFLAG_WRITE
)
4333 memcpy(pad_buf
, qc
->buf_virt
+ sg
->length
- qc
->pad_len
,
4336 sg_dma_address(psg
) = ap
->pad_dma
+ (qc
->tag
* ATA_DMA_PAD_SZ
);
4337 sg_dma_len(psg
) = ATA_DMA_PAD_SZ
;
4339 sg
->length
-= qc
->pad_len
;
4340 if (sg
->length
== 0)
4343 DPRINTK("padding done, sg->length=%u pad_len=%u\n",
4344 sg
->length
, qc
->pad_len
);
4352 dma_address
= dma_map_single(ap
->dev
, qc
->buf_virt
,
4354 if (dma_mapping_error(dma_address
)) {
4356 sg
->length
+= qc
->pad_len
;
4360 sg_dma_address(sg
) = dma_address
;
4361 sg_dma_len(sg
) = sg
->length
;
4364 DPRINTK("mapped buffer of %d bytes for %s\n", sg_dma_len(sg
),
4365 qc
->tf
.flags
& ATA_TFLAG_WRITE
? "write" : "read");
4371 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
4372 * @qc: Command with scatter-gather table to be mapped.
4374 * DMA-map the scatter-gather table associated with queued_cmd @qc.
4377 * spin_lock_irqsave(host lock)
4380 * Zero on success, negative on error.
4384 static int ata_sg_setup(struct ata_queued_cmd
*qc
)
4386 struct ata_port
*ap
= qc
->ap
;
4387 struct scatterlist
*sg
= qc
->__sg
;
4388 struct scatterlist
*lsg
= &sg
[qc
->n_elem
- 1];
4389 int n_elem
, pre_n_elem
, dir
, trim_sg
= 0;
4391 VPRINTK("ENTER, ata%u\n", ap
->print_id
);
4392 WARN_ON(!(qc
->flags
& ATA_QCFLAG_SG
));
4394 /* we must lengthen transfers to end on a 32-bit boundary */
4395 qc
->pad_len
= lsg
->length
& 3;
4397 void *pad_buf
= ap
->pad
+ (qc
->tag
* ATA_DMA_PAD_SZ
);
4398 struct scatterlist
*psg
= &qc
->pad_sgent
;
4399 unsigned int offset
;
4401 WARN_ON(qc
->dev
->class != ATA_DEV_ATAPI
);
4403 memset(pad_buf
, 0, ATA_DMA_PAD_SZ
);
4406 * psg->page/offset are used to copy to-be-written
4407 * data in this function or read data in ata_sg_clean.
4409 offset
= lsg
->offset
+ lsg
->length
- qc
->pad_len
;
4410 psg
->page
= nth_page(lsg
->page
, offset
>> PAGE_SHIFT
);
4411 psg
->offset
= offset_in_page(offset
);
4413 if (qc
->tf
.flags
& ATA_TFLAG_WRITE
) {
4414 void *addr
= kmap_atomic(psg
->page
, KM_IRQ0
);
4415 memcpy(pad_buf
, addr
+ psg
->offset
, qc
->pad_len
);
4416 kunmap_atomic(addr
, KM_IRQ0
);
4419 sg_dma_address(psg
) = ap
->pad_dma
+ (qc
->tag
* ATA_DMA_PAD_SZ
);
4420 sg_dma_len(psg
) = ATA_DMA_PAD_SZ
;
4422 lsg
->length
-= qc
->pad_len
;
4423 if (lsg
->length
== 0)
4426 DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n",
4427 qc
->n_elem
- 1, lsg
->length
, qc
->pad_len
);
4430 pre_n_elem
= qc
->n_elem
;
4431 if (trim_sg
&& pre_n_elem
)
4440 n_elem
= dma_map_sg(ap
->dev
, sg
, pre_n_elem
, dir
);
4442 /* restore last sg */
4443 lsg
->length
+= qc
->pad_len
;
4447 DPRINTK("%d sg elements mapped\n", n_elem
);
4450 qc
->n_elem
= n_elem
;
4456 * swap_buf_le16 - swap halves of 16-bit words in place
4457 * @buf: Buffer to swap
4458 * @buf_words: Number of 16-bit words in buffer.
4460 * Swap halves of 16-bit words if needed to convert from
4461 * little-endian byte order to native cpu byte order, or
4465 * Inherited from caller.
4467 void swap_buf_le16(u16
*buf
, unsigned int buf_words
)
4472 for (i
= 0; i
< buf_words
; i
++)
4473 buf
[i
] = le16_to_cpu(buf
[i
]);
4474 #endif /* __BIG_ENDIAN */
4478 * ata_data_xfer - Transfer data by PIO
4479 * @adev: device to target
4481 * @buflen: buffer length
4482 * @write_data: read/write
4484 * Transfer data from/to the device data register by PIO.
4487 * Inherited from caller.
4489 void ata_data_xfer(struct ata_device
*adev
, unsigned char *buf
,
4490 unsigned int buflen
, int write_data
)
4492 struct ata_port
*ap
= adev
->link
->ap
;
4493 unsigned int words
= buflen
>> 1;
4495 /* Transfer multiple of 2 bytes */
4497 iowrite16_rep(ap
->ioaddr
.data_addr
, buf
, words
);
4499 ioread16_rep(ap
->ioaddr
.data_addr
, buf
, words
);
4501 /* Transfer trailing 1 byte, if any. */
4502 if (unlikely(buflen
& 0x01)) {
4503 u16 align_buf
[1] = { 0 };
4504 unsigned char *trailing_buf
= buf
+ buflen
- 1;
4507 memcpy(align_buf
, trailing_buf
, 1);
4508 iowrite16(le16_to_cpu(align_buf
[0]), ap
->ioaddr
.data_addr
);
4510 align_buf
[0] = cpu_to_le16(ioread16(ap
->ioaddr
.data_addr
));
4511 memcpy(trailing_buf
, align_buf
, 1);
4517 * ata_data_xfer_noirq - Transfer data by PIO
4518 * @adev: device to target
4520 * @buflen: buffer length
4521 * @write_data: read/write
4523 * Transfer data from/to the device data register by PIO. Do the
4524 * transfer with interrupts disabled.
4527 * Inherited from caller.
4529 void ata_data_xfer_noirq(struct ata_device
*adev
, unsigned char *buf
,
4530 unsigned int buflen
, int write_data
)
4532 unsigned long flags
;
4533 local_irq_save(flags
);
4534 ata_data_xfer(adev
, buf
, buflen
, write_data
);
4535 local_irq_restore(flags
);
4540 * ata_pio_sector - Transfer a sector of data.
4541 * @qc: Command on going
4543 * Transfer qc->sect_size bytes of data from/to the ATA device.
4546 * Inherited from caller.
4549 static void ata_pio_sector(struct ata_queued_cmd
*qc
)
4551 int do_write
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
);
4552 struct scatterlist
*sg
= qc
->__sg
;
4553 struct ata_port
*ap
= qc
->ap
;
4555 unsigned int offset
;
4558 if (qc
->curbytes
== qc
->nbytes
- qc
->sect_size
)
4559 ap
->hsm_task_state
= HSM_ST_LAST
;
4561 page
= sg
[qc
->cursg
].page
;
4562 offset
= sg
[qc
->cursg
].offset
+ qc
->cursg_ofs
;
4564 /* get the current page and offset */
4565 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
4566 offset
%= PAGE_SIZE
;
4568 DPRINTK("data %s\n", qc
->tf
.flags
& ATA_TFLAG_WRITE
? "write" : "read");
4570 if (PageHighMem(page
)) {
4571 unsigned long flags
;
4573 /* FIXME: use a bounce buffer */
4574 local_irq_save(flags
);
4575 buf
= kmap_atomic(page
, KM_IRQ0
);
4577 /* do the actual data transfer */
4578 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, qc
->sect_size
, do_write
);
4580 kunmap_atomic(buf
, KM_IRQ0
);
4581 local_irq_restore(flags
);
4583 buf
= page_address(page
);
4584 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, qc
->sect_size
, do_write
);
4587 qc
->curbytes
+= qc
->sect_size
;
4588 qc
->cursg_ofs
+= qc
->sect_size
;
4590 if (qc
->cursg_ofs
== (&sg
[qc
->cursg
])->length
) {
4597 * ata_pio_sectors - Transfer one or many sectors.
4598 * @qc: Command on going
4600 * Transfer one or many sectors of data from/to the
4601 * ATA device for the DRQ request.
4604 * Inherited from caller.
4607 static void ata_pio_sectors(struct ata_queued_cmd
*qc
)
4609 if (is_multi_taskfile(&qc
->tf
)) {
4610 /* READ/WRITE MULTIPLE */
4613 WARN_ON(qc
->dev
->multi_count
== 0);
4615 nsect
= min((qc
->nbytes
- qc
->curbytes
) / qc
->sect_size
,
4616 qc
->dev
->multi_count
);
4622 ata_altstatus(qc
->ap
); /* flush */
4626 * atapi_send_cdb - Write CDB bytes to hardware
4627 * @ap: Port to which ATAPI device is attached.
4628 * @qc: Taskfile currently active
4630 * When device has indicated its readiness to accept
4631 * a CDB, this function is called. Send the CDB.
4637 static void atapi_send_cdb(struct ata_port
*ap
, struct ata_queued_cmd
*qc
)
4640 DPRINTK("send cdb\n");
4641 WARN_ON(qc
->dev
->cdb_len
< 12);
4643 ap
->ops
->data_xfer(qc
->dev
, qc
->cdb
, qc
->dev
->cdb_len
, 1);
4644 ata_altstatus(ap
); /* flush */
4646 switch (qc
->tf
.protocol
) {
4647 case ATA_PROT_ATAPI
:
4648 ap
->hsm_task_state
= HSM_ST
;
4650 case ATA_PROT_ATAPI_NODATA
:
4651 ap
->hsm_task_state
= HSM_ST_LAST
;
4653 case ATA_PROT_ATAPI_DMA
:
4654 ap
->hsm_task_state
= HSM_ST_LAST
;
4655 /* initiate bmdma */
4656 ap
->ops
->bmdma_start(qc
);
4662 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
4663 * @qc: Command on going
4664 * @bytes: number of bytes
4666 * Transfer Transfer data from/to the ATAPI device.
4669 * Inherited from caller.
4673 static void __atapi_pio_bytes(struct ata_queued_cmd
*qc
, unsigned int bytes
)
4675 int do_write
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
);
4676 struct scatterlist
*sg
= qc
->__sg
;
4677 struct ata_port
*ap
= qc
->ap
;
4680 unsigned int offset
, count
;
4682 if (qc
->curbytes
+ bytes
>= qc
->nbytes
)
4683 ap
->hsm_task_state
= HSM_ST_LAST
;
4686 if (unlikely(qc
->cursg
>= qc
->n_elem
)) {
4688 * The end of qc->sg is reached and the device expects
4689 * more data to transfer. In order not to overrun qc->sg
4690 * and fulfill length specified in the byte count register,
4691 * - for read case, discard trailing data from the device
4692 * - for write case, padding zero data to the device
4694 u16 pad_buf
[1] = { 0 };
4695 unsigned int words
= bytes
>> 1;
4698 if (words
) /* warning if bytes > 1 */
4699 ata_dev_printk(qc
->dev
, KERN_WARNING
,
4700 "%u bytes trailing data\n", bytes
);
4702 for (i
= 0; i
< words
; i
++)
4703 ap
->ops
->data_xfer(qc
->dev
, (unsigned char*)pad_buf
, 2, do_write
);
4705 ap
->hsm_task_state
= HSM_ST_LAST
;
4709 sg
= &qc
->__sg
[qc
->cursg
];
4712 offset
= sg
->offset
+ qc
->cursg_ofs
;
4714 /* get the current page and offset */
4715 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
4716 offset
%= PAGE_SIZE
;
4718 /* don't overrun current sg */
4719 count
= min(sg
->length
- qc
->cursg_ofs
, bytes
);
4721 /* don't cross page boundaries */
4722 count
= min(count
, (unsigned int)PAGE_SIZE
- offset
);
4724 DPRINTK("data %s\n", qc
->tf
.flags
& ATA_TFLAG_WRITE
? "write" : "read");
4726 if (PageHighMem(page
)) {
4727 unsigned long flags
;
4729 /* FIXME: use bounce buffer */
4730 local_irq_save(flags
);
4731 buf
= kmap_atomic(page
, KM_IRQ0
);
4733 /* do the actual data transfer */
4734 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, count
, do_write
);
4736 kunmap_atomic(buf
, KM_IRQ0
);
4737 local_irq_restore(flags
);
4739 buf
= page_address(page
);
4740 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, count
, do_write
);
4744 qc
->curbytes
+= count
;
4745 qc
->cursg_ofs
+= count
;
4747 if (qc
->cursg_ofs
== sg
->length
) {
4757 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
4758 * @qc: Command on going
4760 * Transfer Transfer data from/to the ATAPI device.
4763 * Inherited from caller.
4766 static void atapi_pio_bytes(struct ata_queued_cmd
*qc
)
4768 struct ata_port
*ap
= qc
->ap
;
4769 struct ata_device
*dev
= qc
->dev
;
4770 unsigned int ireason
, bc_lo
, bc_hi
, bytes
;
4771 int i_write
, do_write
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
) ? 1 : 0;
4773 /* Abuse qc->result_tf for temp storage of intermediate TF
4774 * here to save some kernel stack usage.
4775 * For normal completion, qc->result_tf is not relevant. For
4776 * error, qc->result_tf is later overwritten by ata_qc_complete().
4777 * So, the correctness of qc->result_tf is not affected.
4779 ap
->ops
->tf_read(ap
, &qc
->result_tf
);
4780 ireason
= qc
->result_tf
.nsect
;
4781 bc_lo
= qc
->result_tf
.lbam
;
4782 bc_hi
= qc
->result_tf
.lbah
;
4783 bytes
= (bc_hi
<< 8) | bc_lo
;
4785 /* shall be cleared to zero, indicating xfer of data */
4786 if (ireason
& (1 << 0))
4789 /* make sure transfer direction matches expected */
4790 i_write
= ((ireason
& (1 << 1)) == 0) ? 1 : 0;
4791 if (do_write
!= i_write
)
4794 VPRINTK("ata%u: xfering %d bytes\n", ap
->print_id
, bytes
);
4796 __atapi_pio_bytes(qc
, bytes
);
4797 ata_altstatus(ap
); /* flush */
4802 ata_dev_printk(dev
, KERN_INFO
, "ATAPI check failed\n");
4803 qc
->err_mask
|= AC_ERR_HSM
;
4804 ap
->hsm_task_state
= HSM_ST_ERR
;
4808 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
4809 * @ap: the target ata_port
4813 * 1 if ok in workqueue, 0 otherwise.
4816 static inline int ata_hsm_ok_in_wq(struct ata_port
*ap
, struct ata_queued_cmd
*qc
)
4818 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
4821 if (ap
->hsm_task_state
== HSM_ST_FIRST
) {
4822 if (qc
->tf
.protocol
== ATA_PROT_PIO
&&
4823 (qc
->tf
.flags
& ATA_TFLAG_WRITE
))
4826 if (is_atapi_taskfile(&qc
->tf
) &&
4827 !(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
4835 * ata_hsm_qc_complete - finish a qc running on standard HSM
4836 * @qc: Command to complete
4837 * @in_wq: 1 if called from workqueue, 0 otherwise
4839 * Finish @qc which is running on standard HSM.
4842 * If @in_wq is zero, spin_lock_irqsave(host lock).
4843 * Otherwise, none on entry and grabs host lock.
4845 static void ata_hsm_qc_complete(struct ata_queued_cmd
*qc
, int in_wq
)
4847 struct ata_port
*ap
= qc
->ap
;
4848 unsigned long flags
;
4850 if (ap
->ops
->error_handler
) {
4852 spin_lock_irqsave(ap
->lock
, flags
);
4854 /* EH might have kicked in while host lock is
4857 qc
= ata_qc_from_tag(ap
, qc
->tag
);
4859 if (likely(!(qc
->err_mask
& AC_ERR_HSM
))) {
4860 ap
->ops
->irq_on(ap
);
4861 ata_qc_complete(qc
);
4863 ata_port_freeze(ap
);
4866 spin_unlock_irqrestore(ap
->lock
, flags
);
4868 if (likely(!(qc
->err_mask
& AC_ERR_HSM
)))
4869 ata_qc_complete(qc
);
4871 ata_port_freeze(ap
);
4875 spin_lock_irqsave(ap
->lock
, flags
);
4876 ap
->ops
->irq_on(ap
);
4877 ata_qc_complete(qc
);
4878 spin_unlock_irqrestore(ap
->lock
, flags
);
4880 ata_qc_complete(qc
);
4885 * ata_hsm_move - move the HSM to the next state.
4886 * @ap: the target ata_port
4888 * @status: current device status
4889 * @in_wq: 1 if called from workqueue, 0 otherwise
4892 * 1 when poll next status needed, 0 otherwise.
4894 int ata_hsm_move(struct ata_port
*ap
, struct ata_queued_cmd
*qc
,
4895 u8 status
, int in_wq
)
4897 unsigned long flags
= 0;
4900 WARN_ON((qc
->flags
& ATA_QCFLAG_ACTIVE
) == 0);
4902 /* Make sure ata_qc_issue_prot() does not throw things
4903 * like DMA polling into the workqueue. Notice that
4904 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING).
4906 WARN_ON(in_wq
!= ata_hsm_ok_in_wq(ap
, qc
));
4909 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
4910 ap
->print_id
, qc
->tf
.protocol
, ap
->hsm_task_state
, status
);
4912 switch (ap
->hsm_task_state
) {
4914 /* Send first data block or PACKET CDB */
4916 /* If polling, we will stay in the work queue after
4917 * sending the data. Otherwise, interrupt handler
4918 * takes over after sending the data.
4920 poll_next
= (qc
->tf
.flags
& ATA_TFLAG_POLLING
);
4922 /* check device status */
4923 if (unlikely((status
& ATA_DRQ
) == 0)) {
4924 /* handle BSY=0, DRQ=0 as error */
4925 if (likely(status
& (ATA_ERR
| ATA_DF
)))
4926 /* device stops HSM for abort/error */
4927 qc
->err_mask
|= AC_ERR_DEV
;
4929 /* HSM violation. Let EH handle this */
4930 qc
->err_mask
|= AC_ERR_HSM
;
4932 ap
->hsm_task_state
= HSM_ST_ERR
;
4936 /* Device should not ask for data transfer (DRQ=1)
4937 * when it finds something wrong.
4938 * We ignore DRQ here and stop the HSM by
4939 * changing hsm_task_state to HSM_ST_ERR and
4940 * let the EH abort the command or reset the device.
4942 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
4943 ata_port_printk(ap
, KERN_WARNING
, "DRQ=1 with device "
4944 "error, dev_stat 0x%X\n", status
);
4945 qc
->err_mask
|= AC_ERR_HSM
;
4946 ap
->hsm_task_state
= HSM_ST_ERR
;
4950 /* Send the CDB (atapi) or the first data block (ata pio out).
4951 * During the state transition, interrupt handler shouldn't
4952 * be invoked before the data transfer is complete and
4953 * hsm_task_state is changed. Hence, the following locking.
4956 spin_lock_irqsave(ap
->lock
, flags
);
4958 if (qc
->tf
.protocol
== ATA_PROT_PIO
) {
4959 /* PIO data out protocol.
4960 * send first data block.
4963 /* ata_pio_sectors() might change the state
4964 * to HSM_ST_LAST. so, the state is changed here
4965 * before ata_pio_sectors().
4967 ap
->hsm_task_state
= HSM_ST
;
4968 ata_pio_sectors(qc
);
4971 atapi_send_cdb(ap
, qc
);
4974 spin_unlock_irqrestore(ap
->lock
, flags
);
4976 /* if polling, ata_pio_task() handles the rest.
4977 * otherwise, interrupt handler takes over from here.
4982 /* complete command or read/write the data register */
4983 if (qc
->tf
.protocol
== ATA_PROT_ATAPI
) {
4984 /* ATAPI PIO protocol */
4985 if ((status
& ATA_DRQ
) == 0) {
4986 /* No more data to transfer or device error.
4987 * Device error will be tagged in HSM_ST_LAST.
4989 ap
->hsm_task_state
= HSM_ST_LAST
;
4993 /* Device should not ask for data transfer (DRQ=1)
4994 * when it finds something wrong.
4995 * We ignore DRQ here and stop the HSM by
4996 * changing hsm_task_state to HSM_ST_ERR and
4997 * let the EH abort the command or reset the device.
4999 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
5000 ata_port_printk(ap
, KERN_WARNING
, "DRQ=1 with "
5001 "device error, dev_stat 0x%X\n",
5003 qc
->err_mask
|= AC_ERR_HSM
;
5004 ap
->hsm_task_state
= HSM_ST_ERR
;
5008 atapi_pio_bytes(qc
);
5010 if (unlikely(ap
->hsm_task_state
== HSM_ST_ERR
))
5011 /* bad ireason reported by device */
5015 /* ATA PIO protocol */
5016 if (unlikely((status
& ATA_DRQ
) == 0)) {
5017 /* handle BSY=0, DRQ=0 as error */
5018 if (likely(status
& (ATA_ERR
| ATA_DF
)))
5019 /* device stops HSM for abort/error */
5020 qc
->err_mask
|= AC_ERR_DEV
;
5022 /* HSM violation. Let EH handle this.
5023 * Phantom devices also trigger this
5024 * condition. Mark hint.
5026 qc
->err_mask
|= AC_ERR_HSM
|
5029 ap
->hsm_task_state
= HSM_ST_ERR
;
5033 /* For PIO reads, some devices may ask for
5034 * data transfer (DRQ=1) alone with ERR=1.
5035 * We respect DRQ here and transfer one
5036 * block of junk data before changing the
5037 * hsm_task_state to HSM_ST_ERR.
5039 * For PIO writes, ERR=1 DRQ=1 doesn't make
5040 * sense since the data block has been
5041 * transferred to the device.
5043 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
5044 /* data might be corrputed */
5045 qc
->err_mask
|= AC_ERR_DEV
;
5047 if (!(qc
->tf
.flags
& ATA_TFLAG_WRITE
)) {
5048 ata_pio_sectors(qc
);
5049 status
= ata_wait_idle(ap
);
5052 if (status
& (ATA_BUSY
| ATA_DRQ
))
5053 qc
->err_mask
|= AC_ERR_HSM
;
5055 /* ata_pio_sectors() might change the
5056 * state to HSM_ST_LAST. so, the state
5057 * is changed after ata_pio_sectors().
5059 ap
->hsm_task_state
= HSM_ST_ERR
;
5063 ata_pio_sectors(qc
);
5065 if (ap
->hsm_task_state
== HSM_ST_LAST
&&
5066 (!(qc
->tf
.flags
& ATA_TFLAG_WRITE
))) {
5068 status
= ata_wait_idle(ap
);
5077 if (unlikely(!ata_ok(status
))) {
5078 qc
->err_mask
|= __ac_err_mask(status
);
5079 ap
->hsm_task_state
= HSM_ST_ERR
;
5083 /* no more data to transfer */
5084 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n",
5085 ap
->print_id
, qc
->dev
->devno
, status
);
5087 WARN_ON(qc
->err_mask
);
5089 ap
->hsm_task_state
= HSM_ST_IDLE
;
5091 /* complete taskfile transaction */
5092 ata_hsm_qc_complete(qc
, in_wq
);
5098 /* make sure qc->err_mask is available to
5099 * know what's wrong and recover
5101 WARN_ON(qc
->err_mask
== 0);
5103 ap
->hsm_task_state
= HSM_ST_IDLE
;
5105 /* complete taskfile transaction */
5106 ata_hsm_qc_complete(qc
, in_wq
);
5118 static void ata_pio_task(struct work_struct
*work
)
5120 struct ata_port
*ap
=
5121 container_of(work
, struct ata_port
, port_task
.work
);
5122 struct ata_queued_cmd
*qc
= ap
->port_task_data
;
5127 WARN_ON(ap
->hsm_task_state
== HSM_ST_IDLE
);
5130 * This is purely heuristic. This is a fast path.
5131 * Sometimes when we enter, BSY will be cleared in
5132 * a chk-status or two. If not, the drive is probably seeking
5133 * or something. Snooze for a couple msecs, then
5134 * chk-status again. If still busy, queue delayed work.
5136 status
= ata_busy_wait(ap
, ATA_BUSY
, 5);
5137 if (status
& ATA_BUSY
) {
5139 status
= ata_busy_wait(ap
, ATA_BUSY
, 10);
5140 if (status
& ATA_BUSY
) {
5141 ata_port_queue_task(ap
, ata_pio_task
, qc
, ATA_SHORT_PAUSE
);
5147 poll_next
= ata_hsm_move(ap
, qc
, status
, 1);
5149 /* another command or interrupt handler
5150 * may be running at this point.
5157 * ata_qc_new - Request an available ATA command, for queueing
5158 * @ap: Port associated with device @dev
5159 * @dev: Device from whom we request an available command structure
5165 static struct ata_queued_cmd
*ata_qc_new(struct ata_port
*ap
)
5167 struct ata_queued_cmd
*qc
= NULL
;
5170 /* no command while frozen */
5171 if (unlikely(ap
->pflags
& ATA_PFLAG_FROZEN
))
5174 /* the last tag is reserved for internal command. */
5175 for (i
= 0; i
< ATA_MAX_QUEUE
- 1; i
++)
5176 if (!test_and_set_bit(i
, &ap
->qc_allocated
)) {
5177 qc
= __ata_qc_from_tag(ap
, i
);
5188 * ata_qc_new_init - Request an available ATA command, and initialize it
5189 * @dev: Device from whom we request an available command structure
5195 struct ata_queued_cmd
*ata_qc_new_init(struct ata_device
*dev
)
5197 struct ata_port
*ap
= dev
->link
->ap
;
5198 struct ata_queued_cmd
*qc
;
5200 qc
= ata_qc_new(ap
);
5213 * ata_qc_free - free unused ata_queued_cmd
5214 * @qc: Command to complete
5216 * Designed to free unused ata_queued_cmd object
5217 * in case something prevents using it.
5220 * spin_lock_irqsave(host lock)
5222 void ata_qc_free(struct ata_queued_cmd
*qc
)
5224 struct ata_port
*ap
= qc
->ap
;
5227 WARN_ON(qc
== NULL
); /* ata_qc_from_tag _might_ return NULL */
5231 if (likely(ata_tag_valid(tag
))) {
5232 qc
->tag
= ATA_TAG_POISON
;
5233 clear_bit(tag
, &ap
->qc_allocated
);
5237 void __ata_qc_complete(struct ata_queued_cmd
*qc
)
5239 struct ata_port
*ap
= qc
->ap
;
5240 struct ata_link
*link
= qc
->dev
->link
;
5242 WARN_ON(qc
== NULL
); /* ata_qc_from_tag _might_ return NULL */
5243 WARN_ON(!(qc
->flags
& ATA_QCFLAG_ACTIVE
));
5245 if (likely(qc
->flags
& ATA_QCFLAG_DMAMAP
))
5248 /* command should be marked inactive atomically with qc completion */
5249 if (qc
->tf
.protocol
== ATA_PROT_NCQ
)
5250 link
->sactive
&= ~(1 << qc
->tag
);
5252 link
->active_tag
= ATA_TAG_POISON
;
5254 /* atapi: mark qc as inactive to prevent the interrupt handler
5255 * from completing the command twice later, before the error handler
5256 * is called. (when rc != 0 and atapi request sense is needed)
5258 qc
->flags
&= ~ATA_QCFLAG_ACTIVE
;
5259 ap
->qc_active
&= ~(1 << qc
->tag
);
5261 /* call completion callback */
5262 qc
->complete_fn(qc
);
5265 static void fill_result_tf(struct ata_queued_cmd
*qc
)
5267 struct ata_port
*ap
= qc
->ap
;
5269 qc
->result_tf
.flags
= qc
->tf
.flags
;
5270 ap
->ops
->tf_read(ap
, &qc
->result_tf
);
5274 * ata_qc_complete - Complete an active ATA command
5275 * @qc: Command to complete
5276 * @err_mask: ATA Status register contents
5278 * Indicate to the mid and upper layers that an ATA
5279 * command has completed, with either an ok or not-ok status.
5282 * spin_lock_irqsave(host lock)
5284 void ata_qc_complete(struct ata_queued_cmd
*qc
)
5286 struct ata_port
*ap
= qc
->ap
;
5288 /* XXX: New EH and old EH use different mechanisms to
5289 * synchronize EH with regular execution path.
5291 * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED.
5292 * Normal execution path is responsible for not accessing a
5293 * failed qc. libata core enforces the rule by returning NULL
5294 * from ata_qc_from_tag() for failed qcs.
5296 * Old EH depends on ata_qc_complete() nullifying completion
5297 * requests if ATA_QCFLAG_EH_SCHEDULED is set. Old EH does
5298 * not synchronize with interrupt handler. Only PIO task is
5301 if (ap
->ops
->error_handler
) {
5302 WARN_ON(ap
->pflags
& ATA_PFLAG_FROZEN
);
5304 if (unlikely(qc
->err_mask
))
5305 qc
->flags
|= ATA_QCFLAG_FAILED
;
5307 if (unlikely(qc
->flags
& ATA_QCFLAG_FAILED
)) {
5308 if (!ata_tag_internal(qc
->tag
)) {
5309 /* always fill result TF for failed qc */
5311 ata_qc_schedule_eh(qc
);
5316 /* read result TF if requested */
5317 if (qc
->flags
& ATA_QCFLAG_RESULT_TF
)
5320 __ata_qc_complete(qc
);
5322 if (qc
->flags
& ATA_QCFLAG_EH_SCHEDULED
)
5325 /* read result TF if failed or requested */
5326 if (qc
->err_mask
|| qc
->flags
& ATA_QCFLAG_RESULT_TF
)
5329 __ata_qc_complete(qc
);
5334 * ata_qc_complete_multiple - Complete multiple qcs successfully
5335 * @ap: port in question
5336 * @qc_active: new qc_active mask
5337 * @finish_qc: LLDD callback invoked before completing a qc
5339 * Complete in-flight commands. This functions is meant to be
5340 * called from low-level driver's interrupt routine to complete
5341 * requests normally. ap->qc_active and @qc_active is compared
5342 * and commands are completed accordingly.
5345 * spin_lock_irqsave(host lock)
5348 * Number of completed commands on success, -errno otherwise.
5350 int ata_qc_complete_multiple(struct ata_port
*ap
, u32 qc_active
,
5351 void (*finish_qc
)(struct ata_queued_cmd
*))
5357 done_mask
= ap
->qc_active
^ qc_active
;
5359 if (unlikely(done_mask
& qc_active
)) {
5360 ata_port_printk(ap
, KERN_ERR
, "illegal qc_active transition "
5361 "(%08x->%08x)\n", ap
->qc_active
, qc_active
);
5365 for (i
= 0; i
< ATA_MAX_QUEUE
; i
++) {
5366 struct ata_queued_cmd
*qc
;
5368 if (!(done_mask
& (1 << i
)))
5371 if ((qc
= ata_qc_from_tag(ap
, i
))) {
5374 ata_qc_complete(qc
);
5382 static inline int ata_should_dma_map(struct ata_queued_cmd
*qc
)
5384 struct ata_port
*ap
= qc
->ap
;
5386 switch (qc
->tf
.protocol
) {
5389 case ATA_PROT_ATAPI_DMA
:
5392 case ATA_PROT_ATAPI
:
5394 if (ap
->flags
& ATA_FLAG_PIO_DMA
)
5407 * ata_qc_issue - issue taskfile to device
5408 * @qc: command to issue to device
5410 * Prepare an ATA command to submission to device.
5411 * This includes mapping the data into a DMA-able
5412 * area, filling in the S/G table, and finally
5413 * writing the taskfile to hardware, starting the command.
5416 * spin_lock_irqsave(host lock)
5418 void ata_qc_issue(struct ata_queued_cmd
*qc
)
5420 struct ata_port
*ap
= qc
->ap
;
5421 struct ata_link
*link
= qc
->dev
->link
;
5423 /* Make sure only one non-NCQ command is outstanding. The
5424 * check is skipped for old EH because it reuses active qc to
5425 * request ATAPI sense.
5427 WARN_ON(ap
->ops
->error_handler
&& ata_tag_valid(link
->active_tag
));
5429 if (qc
->tf
.protocol
== ATA_PROT_NCQ
) {
5430 WARN_ON(link
->sactive
& (1 << qc
->tag
));
5431 link
->sactive
|= 1 << qc
->tag
;
5433 WARN_ON(link
->sactive
);
5434 link
->active_tag
= qc
->tag
;
5437 qc
->flags
|= ATA_QCFLAG_ACTIVE
;
5438 ap
->qc_active
|= 1 << qc
->tag
;
5440 if (ata_should_dma_map(qc
)) {
5441 if (qc
->flags
& ATA_QCFLAG_SG
) {
5442 if (ata_sg_setup(qc
))
5444 } else if (qc
->flags
& ATA_QCFLAG_SINGLE
) {
5445 if (ata_sg_setup_one(qc
))
5449 qc
->flags
&= ~ATA_QCFLAG_DMAMAP
;
5452 ap
->ops
->qc_prep(qc
);
5454 qc
->err_mask
|= ap
->ops
->qc_issue(qc
);
5455 if (unlikely(qc
->err_mask
))
5460 qc
->flags
&= ~ATA_QCFLAG_DMAMAP
;
5461 qc
->err_mask
|= AC_ERR_SYSTEM
;
5463 ata_qc_complete(qc
);
5467 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
5468 * @qc: command to issue to device
5470 * Using various libata functions and hooks, this function
5471 * starts an ATA command. ATA commands are grouped into
5472 * classes called "protocols", and issuing each type of protocol
5473 * is slightly different.
5475 * May be used as the qc_issue() entry in ata_port_operations.
5478 * spin_lock_irqsave(host lock)
5481 * Zero on success, AC_ERR_* mask on failure
5484 unsigned int ata_qc_issue_prot(struct ata_queued_cmd
*qc
)
5486 struct ata_port
*ap
= qc
->ap
;
5488 /* Use polling pio if the LLD doesn't handle
5489 * interrupt driven pio and atapi CDB interrupt.
5491 if (ap
->flags
& ATA_FLAG_PIO_POLLING
) {
5492 switch (qc
->tf
.protocol
) {
5494 case ATA_PROT_NODATA
:
5495 case ATA_PROT_ATAPI
:
5496 case ATA_PROT_ATAPI_NODATA
:
5497 qc
->tf
.flags
|= ATA_TFLAG_POLLING
;
5499 case ATA_PROT_ATAPI_DMA
:
5500 if (qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
)
5501 /* see ata_dma_blacklisted() */
5509 /* select the device */
5510 ata_dev_select(ap
, qc
->dev
->devno
, 1, 0);
5512 /* start the command */
5513 switch (qc
->tf
.protocol
) {
5514 case ATA_PROT_NODATA
:
5515 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5516 ata_qc_set_polling(qc
);
5518 ata_tf_to_host(ap
, &qc
->tf
);
5519 ap
->hsm_task_state
= HSM_ST_LAST
;
5521 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5522 ata_port_queue_task(ap
, ata_pio_task
, qc
, 0);
5527 WARN_ON(qc
->tf
.flags
& ATA_TFLAG_POLLING
);
5529 ap
->ops
->tf_load(ap
, &qc
->tf
); /* load tf registers */
5530 ap
->ops
->bmdma_setup(qc
); /* set up bmdma */
5531 ap
->ops
->bmdma_start(qc
); /* initiate bmdma */
5532 ap
->hsm_task_state
= HSM_ST_LAST
;
5536 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5537 ata_qc_set_polling(qc
);
5539 ata_tf_to_host(ap
, &qc
->tf
);
5541 if (qc
->tf
.flags
& ATA_TFLAG_WRITE
) {
5542 /* PIO data out protocol */
5543 ap
->hsm_task_state
= HSM_ST_FIRST
;
5544 ata_port_queue_task(ap
, ata_pio_task
, qc
, 0);
5546 /* always send first data block using
5547 * the ata_pio_task() codepath.
5550 /* PIO data in protocol */
5551 ap
->hsm_task_state
= HSM_ST
;
5553 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5554 ata_port_queue_task(ap
, ata_pio_task
, qc
, 0);
5556 /* if polling, ata_pio_task() handles the rest.
5557 * otherwise, interrupt handler takes over from here.
5563 case ATA_PROT_ATAPI
:
5564 case ATA_PROT_ATAPI_NODATA
:
5565 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5566 ata_qc_set_polling(qc
);
5568 ata_tf_to_host(ap
, &qc
->tf
);
5570 ap
->hsm_task_state
= HSM_ST_FIRST
;
5572 /* send cdb by polling if no cdb interrupt */
5573 if ((!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
)) ||
5574 (qc
->tf
.flags
& ATA_TFLAG_POLLING
))
5575 ata_port_queue_task(ap
, ata_pio_task
, qc
, 0);
5578 case ATA_PROT_ATAPI_DMA
:
5579 WARN_ON(qc
->tf
.flags
& ATA_TFLAG_POLLING
);
5581 ap
->ops
->tf_load(ap
, &qc
->tf
); /* load tf registers */
5582 ap
->ops
->bmdma_setup(qc
); /* set up bmdma */
5583 ap
->hsm_task_state
= HSM_ST_FIRST
;
5585 /* send cdb by polling if no cdb interrupt */
5586 if (!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
5587 ata_port_queue_task(ap
, ata_pio_task
, qc
, 0);
5592 return AC_ERR_SYSTEM
;
5599 * ata_host_intr - Handle host interrupt for given (port, task)
5600 * @ap: Port on which interrupt arrived (possibly...)
5601 * @qc: Taskfile currently active in engine
5603 * Handle host interrupt for given queued command. Currently,
5604 * only DMA interrupts are handled. All other commands are
5605 * handled via polling with interrupts disabled (nIEN bit).
5608 * spin_lock_irqsave(host lock)
5611 * One if interrupt was handled, zero if not (shared irq).
5614 inline unsigned int ata_host_intr (struct ata_port
*ap
,
5615 struct ata_queued_cmd
*qc
)
5617 struct ata_eh_info
*ehi
= &ap
->link
.eh_info
;
5618 u8 status
, host_stat
= 0;
5620 VPRINTK("ata%u: protocol %d task_state %d\n",
5621 ap
->print_id
, qc
->tf
.protocol
, ap
->hsm_task_state
);
5623 /* Check whether we are expecting interrupt in this state */
5624 switch (ap
->hsm_task_state
) {
5626 /* Some pre-ATAPI-4 devices assert INTRQ
5627 * at this state when ready to receive CDB.
5630 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
5631 * The flag was turned on only for atapi devices.
5632 * No need to check is_atapi_taskfile(&qc->tf) again.
5634 if (!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
5638 if (qc
->tf
.protocol
== ATA_PROT_DMA
||
5639 qc
->tf
.protocol
== ATA_PROT_ATAPI_DMA
) {
5640 /* check status of DMA engine */
5641 host_stat
= ap
->ops
->bmdma_status(ap
);
5642 VPRINTK("ata%u: host_stat 0x%X\n",
5643 ap
->print_id
, host_stat
);
5645 /* if it's not our irq... */
5646 if (!(host_stat
& ATA_DMA_INTR
))
5649 /* before we do anything else, clear DMA-Start bit */
5650 ap
->ops
->bmdma_stop(qc
);
5652 if (unlikely(host_stat
& ATA_DMA_ERR
)) {
5653 /* error when transfering data to/from memory */
5654 qc
->err_mask
|= AC_ERR_HOST_BUS
;
5655 ap
->hsm_task_state
= HSM_ST_ERR
;
5665 /* check altstatus */
5666 status
= ata_altstatus(ap
);
5667 if (status
& ATA_BUSY
)
5670 /* check main status, clearing INTRQ */
5671 status
= ata_chk_status(ap
);
5672 if (unlikely(status
& ATA_BUSY
))
5675 /* ack bmdma irq events */
5676 ap
->ops
->irq_clear(ap
);
5678 ata_hsm_move(ap
, qc
, status
, 0);
5680 if (unlikely(qc
->err_mask
) && (qc
->tf
.protocol
== ATA_PROT_DMA
||
5681 qc
->tf
.protocol
== ATA_PROT_ATAPI_DMA
))
5682 ata_ehi_push_desc(ehi
, "BMDMA stat 0x%x", host_stat
);
5684 return 1; /* irq handled */
5687 ap
->stats
.idle_irq
++;
5690 if ((ap
->stats
.idle_irq
% 1000) == 0) {
5691 ap
->ops
->irq_ack(ap
, 0); /* debug trap */
5692 ata_port_printk(ap
, KERN_WARNING
, "irq trap\n");
5696 return 0; /* irq not handled */
5700 * ata_interrupt - Default ATA host interrupt handler
5701 * @irq: irq line (unused)
5702 * @dev_instance: pointer to our ata_host information structure
5704 * Default interrupt handler for PCI IDE devices. Calls
5705 * ata_host_intr() for each port that is not disabled.
5708 * Obtains host lock during operation.
5711 * IRQ_NONE or IRQ_HANDLED.
5714 irqreturn_t
ata_interrupt (int irq
, void *dev_instance
)
5716 struct ata_host
*host
= dev_instance
;
5718 unsigned int handled
= 0;
5719 unsigned long flags
;
5721 /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */
5722 spin_lock_irqsave(&host
->lock
, flags
);
5724 for (i
= 0; i
< host
->n_ports
; i
++) {
5725 struct ata_port
*ap
;
5727 ap
= host
->ports
[i
];
5729 !(ap
->flags
& ATA_FLAG_DISABLED
)) {
5730 struct ata_queued_cmd
*qc
;
5732 qc
= ata_qc_from_tag(ap
, ap
->link
.active_tag
);
5733 if (qc
&& (!(qc
->tf
.flags
& ATA_TFLAG_POLLING
)) &&
5734 (qc
->flags
& ATA_QCFLAG_ACTIVE
))
5735 handled
|= ata_host_intr(ap
, qc
);
5739 spin_unlock_irqrestore(&host
->lock
, flags
);
5741 return IRQ_RETVAL(handled
);
5745 * sata_scr_valid - test whether SCRs are accessible
5746 * @link: ATA link to test SCR accessibility for
5748 * Test whether SCRs are accessible for @link.
5754 * 1 if SCRs are accessible, 0 otherwise.
5756 int sata_scr_valid(struct ata_link
*link
)
5758 struct ata_port
*ap
= link
->ap
;
5760 return (ap
->flags
& ATA_FLAG_SATA
) && ap
->ops
->scr_read
;
5764 * sata_scr_read - read SCR register of the specified port
5765 * @link: ATA link to read SCR for
5767 * @val: Place to store read value
5769 * Read SCR register @reg of @link into *@val. This function is
5770 * guaranteed to succeed if the cable type of the port is SATA
5771 * and the port implements ->scr_read.
5777 * 0 on success, negative errno on failure.
5779 int sata_scr_read(struct ata_link
*link
, int reg
, u32
*val
)
5781 struct ata_port
*ap
= link
->ap
;
5783 if (sata_scr_valid(link
))
5784 return ap
->ops
->scr_read(ap
, reg
, val
);
5789 * sata_scr_write - write SCR register of the specified port
5790 * @link: ATA link to write SCR for
5791 * @reg: SCR to write
5792 * @val: value to write
5794 * Write @val to SCR register @reg of @link. This function is
5795 * guaranteed to succeed if the cable type of the port is SATA
5796 * and the port implements ->scr_read.
5802 * 0 on success, negative errno on failure.
5804 int sata_scr_write(struct ata_link
*link
, int reg
, u32 val
)
5806 struct ata_port
*ap
= link
->ap
;
5808 if (sata_scr_valid(link
))
5809 return ap
->ops
->scr_write(ap
, reg
, val
);
5814 * sata_scr_write_flush - write SCR register of the specified port and flush
5815 * @link: ATA link to write SCR for
5816 * @reg: SCR to write
5817 * @val: value to write
5819 * This function is identical to sata_scr_write() except that this
5820 * function performs flush after writing to the register.
5826 * 0 on success, negative errno on failure.
5828 int sata_scr_write_flush(struct ata_link
*link
, int reg
, u32 val
)
5830 struct ata_port
*ap
= link
->ap
;
5833 if (sata_scr_valid(link
)) {
5834 rc
= ap
->ops
->scr_write(ap
, reg
, val
);
5836 rc
= ap
->ops
->scr_read(ap
, reg
, &val
);
5843 * ata_link_online - test whether the given link is online
5844 * @link: ATA link to test
5846 * Test whether @link is online. Note that this function returns
5847 * 0 if online status of @link cannot be obtained, so
5848 * ata_link_online(link) != !ata_link_offline(link).
5854 * 1 if the port online status is available and online.
5856 int ata_link_online(struct ata_link
*link
)
5860 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
) == 0 &&
5861 (sstatus
& 0xf) == 0x3)
5867 * ata_link_offline - test whether the given link is offline
5868 * @link: ATA link to test
5870 * Test whether @link is offline. Note that this function
5871 * returns 0 if offline status of @link cannot be obtained, so
5872 * ata_link_online(link) != !ata_link_offline(link).
5878 * 1 if the port offline status is available and offline.
5880 int ata_link_offline(struct ata_link
*link
)
5884 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
) == 0 &&
5885 (sstatus
& 0xf) != 0x3)
5890 int ata_flush_cache(struct ata_device
*dev
)
5892 unsigned int err_mask
;
5895 if (!ata_try_flush_cache(dev
))
5898 if (dev
->flags
& ATA_DFLAG_FLUSH_EXT
)
5899 cmd
= ATA_CMD_FLUSH_EXT
;
5901 cmd
= ATA_CMD_FLUSH
;
5903 err_mask
= ata_do_simple_cmd(dev
, cmd
);
5905 ata_dev_printk(dev
, KERN_ERR
, "failed to flush cache\n");
5913 static int ata_host_request_pm(struct ata_host
*host
, pm_message_t mesg
,
5914 unsigned int action
, unsigned int ehi_flags
,
5917 unsigned long flags
;
5920 for (i
= 0; i
< host
->n_ports
; i
++) {
5921 struct ata_port
*ap
= host
->ports
[i
];
5922 struct ata_link
*link
;
5924 /* Previous resume operation might still be in
5925 * progress. Wait for PM_PENDING to clear.
5927 if (ap
->pflags
& ATA_PFLAG_PM_PENDING
) {
5928 ata_port_wait_eh(ap
);
5929 WARN_ON(ap
->pflags
& ATA_PFLAG_PM_PENDING
);
5932 /* request PM ops to EH */
5933 spin_lock_irqsave(ap
->lock
, flags
);
5938 ap
->pm_result
= &rc
;
5941 ap
->pflags
|= ATA_PFLAG_PM_PENDING
;
5942 __ata_port_for_each_link(link
, ap
) {
5943 link
->eh_info
.action
|= action
;
5944 link
->eh_info
.flags
|= ehi_flags
;
5947 ata_port_schedule_eh(ap
);
5949 spin_unlock_irqrestore(ap
->lock
, flags
);
5951 /* wait and check result */
5953 ata_port_wait_eh(ap
);
5954 WARN_ON(ap
->pflags
& ATA_PFLAG_PM_PENDING
);
5964 * ata_host_suspend - suspend host
5965 * @host: host to suspend
5968 * Suspend @host. Actual operation is performed by EH. This
5969 * function requests EH to perform PM operations and waits for EH
5973 * Kernel thread context (may sleep).
5976 * 0 on success, -errno on failure.
5978 int ata_host_suspend(struct ata_host
*host
, pm_message_t mesg
)
5982 rc
= ata_host_request_pm(host
, mesg
, 0, ATA_EHI_QUIET
, 1);
5984 host
->dev
->power
.power_state
= mesg
;
5989 * ata_host_resume - resume host
5990 * @host: host to resume
5992 * Resume @host. Actual operation is performed by EH. This
5993 * function requests EH to perform PM operations and returns.
5994 * Note that all resume operations are performed parallely.
5997 * Kernel thread context (may sleep).
5999 void ata_host_resume(struct ata_host
*host
)
6001 ata_host_request_pm(host
, PMSG_ON
, ATA_EH_SOFTRESET
,
6002 ATA_EHI_NO_AUTOPSY
| ATA_EHI_QUIET
, 0);
6003 host
->dev
->power
.power_state
= PMSG_ON
;
6008 * ata_port_start - Set port up for dma.
6009 * @ap: Port to initialize
6011 * Called just after data structures for each port are
6012 * initialized. Allocates space for PRD table.
6014 * May be used as the port_start() entry in ata_port_operations.
6017 * Inherited from caller.
6019 int ata_port_start(struct ata_port
*ap
)
6021 struct device
*dev
= ap
->dev
;
6024 ap
->prd
= dmam_alloc_coherent(dev
, ATA_PRD_TBL_SZ
, &ap
->prd_dma
,
6029 rc
= ata_pad_alloc(ap
, dev
);
6033 DPRINTK("prd alloc, virt %p, dma %llx\n", ap
->prd
,
6034 (unsigned long long)ap
->prd_dma
);
6039 * ata_dev_init - Initialize an ata_device structure
6040 * @dev: Device structure to initialize
6042 * Initialize @dev in preparation for probing.
6045 * Inherited from caller.
6047 void ata_dev_init(struct ata_device
*dev
)
6049 struct ata_link
*link
= dev
->link
;
6050 struct ata_port
*ap
= link
->ap
;
6051 unsigned long flags
;
6053 /* SATA spd limit is bound to the first device */
6054 link
->sata_spd_limit
= link
->hw_sata_spd_limit
;
6057 /* High bits of dev->flags are used to record warm plug
6058 * requests which occur asynchronously. Synchronize using
6061 spin_lock_irqsave(ap
->lock
, flags
);
6062 dev
->flags
&= ~ATA_DFLAG_INIT_MASK
;
6064 spin_unlock_irqrestore(ap
->lock
, flags
);
6066 memset((void *)dev
+ ATA_DEVICE_CLEAR_OFFSET
, 0,
6067 sizeof(*dev
) - ATA_DEVICE_CLEAR_OFFSET
);
6068 dev
->pio_mask
= UINT_MAX
;
6069 dev
->mwdma_mask
= UINT_MAX
;
6070 dev
->udma_mask
= UINT_MAX
;
6074 * ata_link_init - Initialize an ata_link structure
6075 * @ap: ATA port link is attached to
6076 * @link: Link structure to initialize
6077 * @pmp: Port multiplier port number
6082 * Kernel thread context (may sleep)
6084 static void ata_link_init(struct ata_port
*ap
, struct ata_link
*link
, int pmp
)
6088 /* clear everything except for devices */
6089 memset(link
, 0, offsetof(struct ata_link
, device
[0]));
6093 link
->active_tag
= ATA_TAG_POISON
;
6094 link
->hw_sata_spd_limit
= UINT_MAX
;
6096 /* can't use iterator, ap isn't initialized yet */
6097 for (i
= 0; i
< ATA_MAX_DEVICES
; i
++) {
6098 struct ata_device
*dev
= &link
->device
[i
];
6101 dev
->devno
= dev
- link
->device
;
6107 * sata_link_init_spd - Initialize link->sata_spd_limit
6108 * @link: Link to configure sata_spd_limit for
6110 * Initialize @link->[hw_]sata_spd_limit to the currently
6114 * Kernel thread context (may sleep).
6117 * 0 on success, -errno on failure.
6119 static int sata_link_init_spd(struct ata_link
*link
)
6124 rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
6128 spd
= (scontrol
>> 4) & 0xf;
6130 link
->hw_sata_spd_limit
&= (1 << spd
) - 1;
6132 link
->sata_spd_limit
= link
->hw_sata_spd_limit
;
6138 * ata_port_alloc - allocate and initialize basic ATA port resources
6139 * @host: ATA host this allocated port belongs to
6141 * Allocate and initialize basic ATA port resources.
6144 * Allocate ATA port on success, NULL on failure.
6147 * Inherited from calling layer (may sleep).
6149 struct ata_port
*ata_port_alloc(struct ata_host
*host
)
6151 struct ata_port
*ap
;
6155 ap
= kzalloc(sizeof(*ap
), GFP_KERNEL
);
6159 ap
->pflags
|= ATA_PFLAG_INITIALIZING
;
6160 ap
->lock
= &host
->lock
;
6161 ap
->flags
= ATA_FLAG_DISABLED
;
6163 ap
->ctl
= ATA_DEVCTL_OBS
;
6165 ap
->dev
= host
->dev
;
6166 ap
->last_ctl
= 0xFF;
6168 #if defined(ATA_VERBOSE_DEBUG)
6169 /* turn on all debugging levels */
6170 ap
->msg_enable
= 0x00FF;
6171 #elif defined(ATA_DEBUG)
6172 ap
->msg_enable
= ATA_MSG_DRV
| ATA_MSG_INFO
| ATA_MSG_CTL
| ATA_MSG_WARN
| ATA_MSG_ERR
;
6174 ap
->msg_enable
= ATA_MSG_DRV
| ATA_MSG_ERR
| ATA_MSG_WARN
;
6177 INIT_DELAYED_WORK(&ap
->port_task
, NULL
);
6178 INIT_DELAYED_WORK(&ap
->hotplug_task
, ata_scsi_hotplug
);
6179 INIT_WORK(&ap
->scsi_rescan_task
, ata_scsi_dev_rescan
);
6180 INIT_LIST_HEAD(&ap
->eh_done_q
);
6181 init_waitqueue_head(&ap
->eh_wait_q
);
6182 init_timer_deferrable(&ap
->fastdrain_timer
);
6183 ap
->fastdrain_timer
.function
= ata_eh_fastdrain_timerfn
;
6184 ap
->fastdrain_timer
.data
= (unsigned long)ap
;
6186 ap
->cbl
= ATA_CBL_NONE
;
6188 ata_link_init(ap
, &ap
->link
, 0);
6191 ap
->stats
.unhandled_irq
= 1;
6192 ap
->stats
.idle_irq
= 1;
6197 static void ata_host_release(struct device
*gendev
, void *res
)
6199 struct ata_host
*host
= dev_get_drvdata(gendev
);
6202 for (i
= 0; i
< host
->n_ports
; i
++) {
6203 struct ata_port
*ap
= host
->ports
[i
];
6208 if ((host
->flags
& ATA_HOST_STARTED
) && ap
->ops
->port_stop
)
6209 ap
->ops
->port_stop(ap
);
6212 if ((host
->flags
& ATA_HOST_STARTED
) && host
->ops
->host_stop
)
6213 host
->ops
->host_stop(host
);
6215 for (i
= 0; i
< host
->n_ports
; i
++) {
6216 struct ata_port
*ap
= host
->ports
[i
];
6222 scsi_host_put(ap
->scsi_host
);
6225 host
->ports
[i
] = NULL
;
6228 dev_set_drvdata(gendev
, NULL
);
6232 * ata_host_alloc - allocate and init basic ATA host resources
6233 * @dev: generic device this host is associated with
6234 * @max_ports: maximum number of ATA ports associated with this host
6236 * Allocate and initialize basic ATA host resources. LLD calls
6237 * this function to allocate a host, initializes it fully and
6238 * attaches it using ata_host_register().
6240 * @max_ports ports are allocated and host->n_ports is
6241 * initialized to @max_ports. The caller is allowed to decrease
6242 * host->n_ports before calling ata_host_register(). The unused
6243 * ports will be automatically freed on registration.
6246 * Allocate ATA host on success, NULL on failure.
6249 * Inherited from calling layer (may sleep).
6251 struct ata_host
*ata_host_alloc(struct device
*dev
, int max_ports
)
6253 struct ata_host
*host
;
6259 if (!devres_open_group(dev
, NULL
, GFP_KERNEL
))
6262 /* alloc a container for our list of ATA ports (buses) */
6263 sz
= sizeof(struct ata_host
) + (max_ports
+ 1) * sizeof(void *);
6264 /* alloc a container for our list of ATA ports (buses) */
6265 host
= devres_alloc(ata_host_release
, sz
, GFP_KERNEL
);
6269 devres_add(dev
, host
);
6270 dev_set_drvdata(dev
, host
);
6272 spin_lock_init(&host
->lock
);
6274 host
->n_ports
= max_ports
;
6276 /* allocate ports bound to this host */
6277 for (i
= 0; i
< max_ports
; i
++) {
6278 struct ata_port
*ap
;
6280 ap
= ata_port_alloc(host
);
6285 host
->ports
[i
] = ap
;
6288 devres_remove_group(dev
, NULL
);
6292 devres_release_group(dev
, NULL
);
6297 * ata_host_alloc_pinfo - alloc host and init with port_info array
6298 * @dev: generic device this host is associated with
6299 * @ppi: array of ATA port_info to initialize host with
6300 * @n_ports: number of ATA ports attached to this host
6302 * Allocate ATA host and initialize with info from @ppi. If NULL
6303 * terminated, @ppi may contain fewer entries than @n_ports. The
6304 * last entry will be used for the remaining ports.
6307 * Allocate ATA host on success, NULL on failure.
6310 * Inherited from calling layer (may sleep).
6312 struct ata_host
*ata_host_alloc_pinfo(struct device
*dev
,
6313 const struct ata_port_info
* const * ppi
,
6316 const struct ata_port_info
*pi
;
6317 struct ata_host
*host
;
6320 host
= ata_host_alloc(dev
, n_ports
);
6324 for (i
= 0, j
= 0, pi
= NULL
; i
< host
->n_ports
; i
++) {
6325 struct ata_port
*ap
= host
->ports
[i
];
6330 ap
->pio_mask
= pi
->pio_mask
;
6331 ap
->mwdma_mask
= pi
->mwdma_mask
;
6332 ap
->udma_mask
= pi
->udma_mask
;
6333 ap
->flags
|= pi
->flags
;
6334 ap
->link
.flags
|= pi
->link_flags
;
6335 ap
->ops
= pi
->port_ops
;
6337 if (!host
->ops
&& (pi
->port_ops
!= &ata_dummy_port_ops
))
6338 host
->ops
= pi
->port_ops
;
6339 if (!host
->private_data
&& pi
->private_data
)
6340 host
->private_data
= pi
->private_data
;
6347 * ata_host_start - start and freeze ports of an ATA host
6348 * @host: ATA host to start ports for
6350 * Start and then freeze ports of @host. Started status is
6351 * recorded in host->flags, so this function can be called
6352 * multiple times. Ports are guaranteed to get started only
6353 * once. If host->ops isn't initialized yet, its set to the
6354 * first non-dummy port ops.
6357 * Inherited from calling layer (may sleep).
6360 * 0 if all ports are started successfully, -errno otherwise.
6362 int ata_host_start(struct ata_host
*host
)
6366 if (host
->flags
& ATA_HOST_STARTED
)
6369 for (i
= 0; i
< host
->n_ports
; i
++) {
6370 struct ata_port
*ap
= host
->ports
[i
];
6372 if (!host
->ops
&& !ata_port_is_dummy(ap
))
6373 host
->ops
= ap
->ops
;
6375 if (ap
->ops
->port_start
) {
6376 rc
= ap
->ops
->port_start(ap
);
6378 ata_port_printk(ap
, KERN_ERR
, "failed to "
6379 "start port (errno=%d)\n", rc
);
6384 ata_eh_freeze_port(ap
);
6387 host
->flags
|= ATA_HOST_STARTED
;
6392 struct ata_port
*ap
= host
->ports
[i
];
6394 if (ap
->ops
->port_stop
)
6395 ap
->ops
->port_stop(ap
);
6401 * ata_sas_host_init - Initialize a host struct
6402 * @host: host to initialize
6403 * @dev: device host is attached to
6404 * @flags: host flags
6408 * PCI/etc. bus probe sem.
6411 /* KILLME - the only user left is ipr */
6412 void ata_host_init(struct ata_host
*host
, struct device
*dev
,
6413 unsigned long flags
, const struct ata_port_operations
*ops
)
6415 spin_lock_init(&host
->lock
);
6417 host
->flags
= flags
;
6422 * ata_host_register - register initialized ATA host
6423 * @host: ATA host to register
6424 * @sht: template for SCSI host
6426 * Register initialized ATA host. @host is allocated using
6427 * ata_host_alloc() and fully initialized by LLD. This function
6428 * starts ports, registers @host with ATA and SCSI layers and
6429 * probe registered devices.
6432 * Inherited from calling layer (may sleep).
6435 * 0 on success, -errno otherwise.
6437 int ata_host_register(struct ata_host
*host
, struct scsi_host_template
*sht
)
6441 /* host must have been started */
6442 if (!(host
->flags
& ATA_HOST_STARTED
)) {
6443 dev_printk(KERN_ERR
, host
->dev
,
6444 "BUG: trying to register unstarted host\n");
6449 /* Blow away unused ports. This happens when LLD can't
6450 * determine the exact number of ports to allocate at
6453 for (i
= host
->n_ports
; host
->ports
[i
]; i
++)
6454 kfree(host
->ports
[i
]);
6456 /* give ports names and add SCSI hosts */
6457 for (i
= 0; i
< host
->n_ports
; i
++)
6458 host
->ports
[i
]->print_id
= ata_print_id
++;
6460 rc
= ata_scsi_add_hosts(host
, sht
);
6464 /* associate with ACPI nodes */
6465 ata_acpi_associate(host
);
6467 /* set cable, sata_spd_limit and report */
6468 for (i
= 0; i
< host
->n_ports
; i
++) {
6469 struct ata_port
*ap
= host
->ports
[i
];
6471 unsigned long xfer_mask
;
6473 /* set SATA cable type if still unset */
6474 if (ap
->cbl
== ATA_CBL_NONE
&& (ap
->flags
& ATA_FLAG_SATA
))
6475 ap
->cbl
= ATA_CBL_SATA
;
6477 /* init sata_spd_limit to the current value */
6478 sata_link_init_spd(&ap
->link
);
6480 /* report the secondary IRQ for second channel legacy */
6481 irq_line
= host
->irq
;
6482 if (i
== 1 && host
->irq2
)
6483 irq_line
= host
->irq2
;
6485 xfer_mask
= ata_pack_xfermask(ap
->pio_mask
, ap
->mwdma_mask
,
6488 /* print per-port info to dmesg */
6489 if (!ata_port_is_dummy(ap
))
6490 ata_port_printk(ap
, KERN_INFO
, "%cATA max %s cmd 0x%p "
6491 "ctl 0x%p bmdma 0x%p irq %d\n",
6492 (ap
->flags
& ATA_FLAG_SATA
) ? 'S' : 'P',
6493 ata_mode_string(xfer_mask
),
6494 ap
->ioaddr
.cmd_addr
,
6495 ap
->ioaddr
.ctl_addr
,
6496 ap
->ioaddr
.bmdma_addr
,
6499 ata_port_printk(ap
, KERN_INFO
, "DUMMY\n");
6502 /* perform each probe synchronously */
6503 DPRINTK("probe begin\n");
6504 for (i
= 0; i
< host
->n_ports
; i
++) {
6505 struct ata_port
*ap
= host
->ports
[i
];
6509 if (ap
->ops
->error_handler
) {
6510 struct ata_eh_info
*ehi
= &ap
->link
.eh_info
;
6511 unsigned long flags
;
6515 /* kick EH for boot probing */
6516 spin_lock_irqsave(ap
->lock
, flags
);
6519 (1 << ata_link_max_devices(&ap
->link
)) - 1;
6520 ehi
->action
|= ATA_EH_SOFTRESET
;
6521 ehi
->flags
|= ATA_EHI_NO_AUTOPSY
| ATA_EHI_QUIET
;
6523 ap
->pflags
&= ~ATA_PFLAG_INITIALIZING
;
6524 ap
->pflags
|= ATA_PFLAG_LOADING
;
6525 ata_port_schedule_eh(ap
);
6527 spin_unlock_irqrestore(ap
->lock
, flags
);
6529 /* wait for EH to finish */
6530 ata_port_wait_eh(ap
);
6532 DPRINTK("ata%u: bus probe begin\n", ap
->print_id
);
6533 rc
= ata_bus_probe(ap
);
6534 DPRINTK("ata%u: bus probe end\n", ap
->print_id
);
6537 /* FIXME: do something useful here?
6538 * Current libata behavior will
6539 * tear down everything when
6540 * the module is removed
6541 * or the h/w is unplugged.
6547 /* probes are done, now scan each port's disk(s) */
6548 DPRINTK("host probe begin\n");
6549 for (i
= 0; i
< host
->n_ports
; i
++) {
6550 struct ata_port
*ap
= host
->ports
[i
];
6552 ata_scsi_scan_host(ap
, 1);
6559 * ata_host_activate - start host, request IRQ and register it
6560 * @host: target ATA host
6561 * @irq: IRQ to request
6562 * @irq_handler: irq_handler used when requesting IRQ
6563 * @irq_flags: irq_flags used when requesting IRQ
6564 * @sht: scsi_host_template to use when registering the host
6566 * After allocating an ATA host and initializing it, most libata
6567 * LLDs perform three steps to activate the host - start host,
6568 * request IRQ and register it. This helper takes necessasry
6569 * arguments and performs the three steps in one go.
6572 * Inherited from calling layer (may sleep).
6575 * 0 on success, -errno otherwise.
6577 int ata_host_activate(struct ata_host
*host
, int irq
,
6578 irq_handler_t irq_handler
, unsigned long irq_flags
,
6579 struct scsi_host_template
*sht
)
6583 rc
= ata_host_start(host
);
6587 rc
= devm_request_irq(host
->dev
, irq
, irq_handler
, irq_flags
,
6588 dev_driver_string(host
->dev
), host
);
6592 /* Used to print device info at probe */
6595 rc
= ata_host_register(host
, sht
);
6596 /* if failed, just free the IRQ and leave ports alone */
6598 devm_free_irq(host
->dev
, irq
, host
);
6604 * ata_port_detach - Detach ATA port in prepration of device removal
6605 * @ap: ATA port to be detached
6607 * Detach all ATA devices and the associated SCSI devices of @ap;
6608 * then, remove the associated SCSI host. @ap is guaranteed to
6609 * be quiescent on return from this function.
6612 * Kernel thread context (may sleep).
6614 void ata_port_detach(struct ata_port
*ap
)
6616 unsigned long flags
;
6617 struct ata_link
*link
;
6618 struct ata_device
*dev
;
6620 if (!ap
->ops
->error_handler
)
6623 /* tell EH we're leaving & flush EH */
6624 spin_lock_irqsave(ap
->lock
, flags
);
6625 ap
->pflags
|= ATA_PFLAG_UNLOADING
;
6626 spin_unlock_irqrestore(ap
->lock
, flags
);
6628 ata_port_wait_eh(ap
);
6630 /* EH is now guaranteed to see UNLOADING, so no new device
6631 * will be attached. Disable all existing devices.
6633 spin_lock_irqsave(ap
->lock
, flags
);
6635 ata_port_for_each_link(link
, ap
) {
6636 ata_link_for_each_dev(dev
, link
)
6637 ata_dev_disable(dev
);
6640 spin_unlock_irqrestore(ap
->lock
, flags
);
6642 /* Final freeze & EH. All in-flight commands are aborted. EH
6643 * will be skipped and retrials will be terminated with bad
6646 spin_lock_irqsave(ap
->lock
, flags
);
6647 ata_port_freeze(ap
); /* won't be thawed */
6648 spin_unlock_irqrestore(ap
->lock
, flags
);
6650 ata_port_wait_eh(ap
);
6651 cancel_rearming_delayed_work(&ap
->hotplug_task
);
6654 /* remove the associated SCSI host */
6655 scsi_remove_host(ap
->scsi_host
);
6659 * ata_host_detach - Detach all ports of an ATA host
6660 * @host: Host to detach
6662 * Detach all ports of @host.
6665 * Kernel thread context (may sleep).
6667 void ata_host_detach(struct ata_host
*host
)
6671 for (i
= 0; i
< host
->n_ports
; i
++)
6672 ata_port_detach(host
->ports
[i
]);
6676 * ata_std_ports - initialize ioaddr with standard port offsets.
6677 * @ioaddr: IO address structure to be initialized
6679 * Utility function which initializes data_addr, error_addr,
6680 * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
6681 * device_addr, status_addr, and command_addr to standard offsets
6682 * relative to cmd_addr.
6684 * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
6687 void ata_std_ports(struct ata_ioports
*ioaddr
)
6689 ioaddr
->data_addr
= ioaddr
->cmd_addr
+ ATA_REG_DATA
;
6690 ioaddr
->error_addr
= ioaddr
->cmd_addr
+ ATA_REG_ERR
;
6691 ioaddr
->feature_addr
= ioaddr
->cmd_addr
+ ATA_REG_FEATURE
;
6692 ioaddr
->nsect_addr
= ioaddr
->cmd_addr
+ ATA_REG_NSECT
;
6693 ioaddr
->lbal_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAL
;
6694 ioaddr
->lbam_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAM
;
6695 ioaddr
->lbah_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAH
;
6696 ioaddr
->device_addr
= ioaddr
->cmd_addr
+ ATA_REG_DEVICE
;
6697 ioaddr
->status_addr
= ioaddr
->cmd_addr
+ ATA_REG_STATUS
;
6698 ioaddr
->command_addr
= ioaddr
->cmd_addr
+ ATA_REG_CMD
;
6705 * ata_pci_remove_one - PCI layer callback for device removal
6706 * @pdev: PCI device that was removed
6708 * PCI layer indicates to libata via this hook that hot-unplug or
6709 * module unload event has occurred. Detach all ports. Resource
6710 * release is handled via devres.
6713 * Inherited from PCI layer (may sleep).
6715 void ata_pci_remove_one(struct pci_dev
*pdev
)
6717 struct device
*dev
= pci_dev_to_dev(pdev
);
6718 struct ata_host
*host
= dev_get_drvdata(dev
);
6720 ata_host_detach(host
);
6723 /* move to PCI subsystem */
6724 int pci_test_config_bits(struct pci_dev
*pdev
, const struct pci_bits
*bits
)
6726 unsigned long tmp
= 0;
6728 switch (bits
->width
) {
6731 pci_read_config_byte(pdev
, bits
->reg
, &tmp8
);
6737 pci_read_config_word(pdev
, bits
->reg
, &tmp16
);
6743 pci_read_config_dword(pdev
, bits
->reg
, &tmp32
);
6754 return (tmp
== bits
->val
) ? 1 : 0;
6758 void ata_pci_device_do_suspend(struct pci_dev
*pdev
, pm_message_t mesg
)
6760 pci_save_state(pdev
);
6761 pci_disable_device(pdev
);
6763 if (mesg
.event
== PM_EVENT_SUSPEND
)
6764 pci_set_power_state(pdev
, PCI_D3hot
);
6767 int ata_pci_device_do_resume(struct pci_dev
*pdev
)
6771 pci_set_power_state(pdev
, PCI_D0
);
6772 pci_restore_state(pdev
);
6774 rc
= pcim_enable_device(pdev
);
6776 dev_printk(KERN_ERR
, &pdev
->dev
,
6777 "failed to enable device after resume (%d)\n", rc
);
6781 pci_set_master(pdev
);
6785 int ata_pci_device_suspend(struct pci_dev
*pdev
, pm_message_t mesg
)
6787 struct ata_host
*host
= dev_get_drvdata(&pdev
->dev
);
6790 rc
= ata_host_suspend(host
, mesg
);
6794 ata_pci_device_do_suspend(pdev
, mesg
);
6799 int ata_pci_device_resume(struct pci_dev
*pdev
)
6801 struct ata_host
*host
= dev_get_drvdata(&pdev
->dev
);
6804 rc
= ata_pci_device_do_resume(pdev
);
6806 ata_host_resume(host
);
6809 #endif /* CONFIG_PM */
6811 #endif /* CONFIG_PCI */
6814 static int __init
ata_init(void)
6816 ata_probe_timeout
*= HZ
;
6817 ata_wq
= create_workqueue("ata");
6821 ata_aux_wq
= create_singlethread_workqueue("ata_aux");
6823 destroy_workqueue(ata_wq
);
6827 printk(KERN_DEBUG
"libata version " DRV_VERSION
" loaded.\n");
6831 static void __exit
ata_exit(void)
6833 destroy_workqueue(ata_wq
);
6834 destroy_workqueue(ata_aux_wq
);
6837 subsys_initcall(ata_init
);
6838 module_exit(ata_exit
);
6840 static unsigned long ratelimit_time
;
6841 static DEFINE_SPINLOCK(ata_ratelimit_lock
);
6843 int ata_ratelimit(void)
6846 unsigned long flags
;
6848 spin_lock_irqsave(&ata_ratelimit_lock
, flags
);
6850 if (time_after(jiffies
, ratelimit_time
)) {
6852 ratelimit_time
= jiffies
+ (HZ
/5);
6856 spin_unlock_irqrestore(&ata_ratelimit_lock
, flags
);
6862 * ata_wait_register - wait until register value changes
6863 * @reg: IO-mapped register
6864 * @mask: Mask to apply to read register value
6865 * @val: Wait condition
6866 * @interval_msec: polling interval in milliseconds
6867 * @timeout_msec: timeout in milliseconds
6869 * Waiting for some bits of register to change is a common
6870 * operation for ATA controllers. This function reads 32bit LE
6871 * IO-mapped register @reg and tests for the following condition.
6873 * (*@reg & mask) != val
6875 * If the condition is met, it returns; otherwise, the process is
6876 * repeated after @interval_msec until timeout.
6879 * Kernel thread context (may sleep)
6882 * The final register value.
6884 u32
ata_wait_register(void __iomem
*reg
, u32 mask
, u32 val
,
6885 unsigned long interval_msec
,
6886 unsigned long timeout_msec
)
6888 unsigned long timeout
;
6891 tmp
= ioread32(reg
);
6893 /* Calculate timeout _after_ the first read to make sure
6894 * preceding writes reach the controller before starting to
6895 * eat away the timeout.
6897 timeout
= jiffies
+ (timeout_msec
* HZ
) / 1000;
6899 while ((tmp
& mask
) == val
&& time_before(jiffies
, timeout
)) {
6900 msleep(interval_msec
);
6901 tmp
= ioread32(reg
);
6910 static void ata_dummy_noret(struct ata_port
*ap
) { }
6911 static int ata_dummy_ret0(struct ata_port
*ap
) { return 0; }
6912 static void ata_dummy_qc_noret(struct ata_queued_cmd
*qc
) { }
6914 static u8
ata_dummy_check_status(struct ata_port
*ap
)
6919 static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd
*qc
)
6921 return AC_ERR_SYSTEM
;
6924 const struct ata_port_operations ata_dummy_port_ops
= {
6925 .port_disable
= ata_port_disable
,
6926 .check_status
= ata_dummy_check_status
,
6927 .check_altstatus
= ata_dummy_check_status
,
6928 .dev_select
= ata_noop_dev_select
,
6929 .qc_prep
= ata_noop_qc_prep
,
6930 .qc_issue
= ata_dummy_qc_issue
,
6931 .freeze
= ata_dummy_noret
,
6932 .thaw
= ata_dummy_noret
,
6933 .error_handler
= ata_dummy_noret
,
6934 .post_internal_cmd
= ata_dummy_qc_noret
,
6935 .irq_clear
= ata_dummy_noret
,
6936 .port_start
= ata_dummy_ret0
,
6937 .port_stop
= ata_dummy_noret
,
6940 const struct ata_port_info ata_dummy_port_info
= {
6941 .port_ops
= &ata_dummy_port_ops
,
6945 * libata is essentially a library of internal helper functions for
6946 * low-level ATA host controller drivers. As such, the API/ABI is
6947 * likely to change as new drivers are added and updated.
6948 * Do not depend on ABI/API stability.
6951 EXPORT_SYMBOL_GPL(sata_deb_timing_normal
);
6952 EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug
);
6953 EXPORT_SYMBOL_GPL(sata_deb_timing_long
);
6954 EXPORT_SYMBOL_GPL(ata_dummy_port_ops
);
6955 EXPORT_SYMBOL_GPL(ata_dummy_port_info
);
6956 EXPORT_SYMBOL_GPL(ata_std_bios_param
);
6957 EXPORT_SYMBOL_GPL(ata_std_ports
);
6958 EXPORT_SYMBOL_GPL(ata_host_init
);
6959 EXPORT_SYMBOL_GPL(ata_host_alloc
);
6960 EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo
);
6961 EXPORT_SYMBOL_GPL(ata_host_start
);
6962 EXPORT_SYMBOL_GPL(ata_host_register
);
6963 EXPORT_SYMBOL_GPL(ata_host_activate
);
6964 EXPORT_SYMBOL_GPL(ata_host_detach
);
6965 EXPORT_SYMBOL_GPL(ata_sg_init
);
6966 EXPORT_SYMBOL_GPL(ata_sg_init_one
);
6967 EXPORT_SYMBOL_GPL(ata_hsm_move
);
6968 EXPORT_SYMBOL_GPL(ata_qc_complete
);
6969 EXPORT_SYMBOL_GPL(ata_qc_complete_multiple
);
6970 EXPORT_SYMBOL_GPL(ata_qc_issue_prot
);
6971 EXPORT_SYMBOL_GPL(ata_tf_load
);
6972 EXPORT_SYMBOL_GPL(ata_tf_read
);
6973 EXPORT_SYMBOL_GPL(ata_noop_dev_select
);
6974 EXPORT_SYMBOL_GPL(ata_std_dev_select
);
6975 EXPORT_SYMBOL_GPL(sata_print_link_status
);
6976 EXPORT_SYMBOL_GPL(ata_tf_to_fis
);
6977 EXPORT_SYMBOL_GPL(ata_tf_from_fis
);
6978 EXPORT_SYMBOL_GPL(ata_check_status
);
6979 EXPORT_SYMBOL_GPL(ata_altstatus
);
6980 EXPORT_SYMBOL_GPL(ata_exec_command
);
6981 EXPORT_SYMBOL_GPL(ata_port_start
);
6982 EXPORT_SYMBOL_GPL(ata_sff_port_start
);
6983 EXPORT_SYMBOL_GPL(ata_interrupt
);
6984 EXPORT_SYMBOL_GPL(ata_do_set_mode
);
6985 EXPORT_SYMBOL_GPL(ata_data_xfer
);
6986 EXPORT_SYMBOL_GPL(ata_data_xfer_noirq
);
6987 EXPORT_SYMBOL_GPL(ata_qc_prep
);
6988 EXPORT_SYMBOL_GPL(ata_dumb_qc_prep
);
6989 EXPORT_SYMBOL_GPL(ata_noop_qc_prep
);
6990 EXPORT_SYMBOL_GPL(ata_bmdma_setup
);
6991 EXPORT_SYMBOL_GPL(ata_bmdma_start
);
6992 EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear
);
6993 EXPORT_SYMBOL_GPL(ata_bmdma_status
);
6994 EXPORT_SYMBOL_GPL(ata_bmdma_stop
);
6995 EXPORT_SYMBOL_GPL(ata_bmdma_freeze
);
6996 EXPORT_SYMBOL_GPL(ata_bmdma_thaw
);
6997 EXPORT_SYMBOL_GPL(ata_bmdma_drive_eh
);
6998 EXPORT_SYMBOL_GPL(ata_bmdma_error_handler
);
6999 EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd
);
7000 EXPORT_SYMBOL_GPL(ata_port_probe
);
7001 EXPORT_SYMBOL_GPL(ata_dev_disable
);
7002 EXPORT_SYMBOL_GPL(sata_set_spd
);
7003 EXPORT_SYMBOL_GPL(sata_link_debounce
);
7004 EXPORT_SYMBOL_GPL(sata_link_resume
);
7005 EXPORT_SYMBOL_GPL(sata_phy_reset
);
7006 EXPORT_SYMBOL_GPL(__sata_phy_reset
);
7007 EXPORT_SYMBOL_GPL(ata_bus_reset
);
7008 EXPORT_SYMBOL_GPL(ata_std_prereset
);
7009 EXPORT_SYMBOL_GPL(ata_std_softreset
);
7010 EXPORT_SYMBOL_GPL(sata_link_hardreset
);
7011 EXPORT_SYMBOL_GPL(sata_std_hardreset
);
7012 EXPORT_SYMBOL_GPL(ata_std_postreset
);
7013 EXPORT_SYMBOL_GPL(ata_dev_classify
);
7014 EXPORT_SYMBOL_GPL(ata_dev_pair
);
7015 EXPORT_SYMBOL_GPL(ata_port_disable
);
7016 EXPORT_SYMBOL_GPL(ata_ratelimit
);
7017 EXPORT_SYMBOL_GPL(ata_wait_register
);
7018 EXPORT_SYMBOL_GPL(ata_busy_sleep
);
7019 EXPORT_SYMBOL_GPL(ata_wait_ready
);
7020 EXPORT_SYMBOL_GPL(ata_port_queue_task
);
7021 EXPORT_SYMBOL_GPL(ata_scsi_ioctl
);
7022 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd
);
7023 EXPORT_SYMBOL_GPL(ata_scsi_slave_config
);
7024 EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy
);
7025 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth
);
7026 EXPORT_SYMBOL_GPL(ata_host_intr
);
7027 EXPORT_SYMBOL_GPL(sata_scr_valid
);
7028 EXPORT_SYMBOL_GPL(sata_scr_read
);
7029 EXPORT_SYMBOL_GPL(sata_scr_write
);
7030 EXPORT_SYMBOL_GPL(sata_scr_write_flush
);
7031 EXPORT_SYMBOL_GPL(ata_link_online
);
7032 EXPORT_SYMBOL_GPL(ata_link_offline
);
7034 EXPORT_SYMBOL_GPL(ata_host_suspend
);
7035 EXPORT_SYMBOL_GPL(ata_host_resume
);
7036 #endif /* CONFIG_PM */
7037 EXPORT_SYMBOL_GPL(ata_id_string
);
7038 EXPORT_SYMBOL_GPL(ata_id_c_string
);
7039 EXPORT_SYMBOL_GPL(ata_id_to_dma_mode
);
7040 EXPORT_SYMBOL_GPL(ata_scsi_simulate
);
7042 EXPORT_SYMBOL_GPL(ata_pio_need_iordy
);
7043 EXPORT_SYMBOL_GPL(ata_timing_compute
);
7044 EXPORT_SYMBOL_GPL(ata_timing_merge
);
7047 EXPORT_SYMBOL_GPL(pci_test_config_bits
);
7048 EXPORT_SYMBOL_GPL(ata_pci_init_sff_host
);
7049 EXPORT_SYMBOL_GPL(ata_pci_init_bmdma
);
7050 EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host
);
7051 EXPORT_SYMBOL_GPL(ata_pci_init_one
);
7052 EXPORT_SYMBOL_GPL(ata_pci_remove_one
);
7054 EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend
);
7055 EXPORT_SYMBOL_GPL(ata_pci_device_do_resume
);
7056 EXPORT_SYMBOL_GPL(ata_pci_device_suspend
);
7057 EXPORT_SYMBOL_GPL(ata_pci_device_resume
);
7058 #endif /* CONFIG_PM */
7059 EXPORT_SYMBOL_GPL(ata_pci_default_filter
);
7060 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex
);
7061 #endif /* CONFIG_PCI */
7063 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc
);
7064 EXPORT_SYMBOL_GPL(ata_ehi_push_desc
);
7065 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc
);
7066 EXPORT_SYMBOL_GPL(ata_eng_timeout
);
7067 EXPORT_SYMBOL_GPL(ata_port_schedule_eh
);
7068 EXPORT_SYMBOL_GPL(ata_link_abort
);
7069 EXPORT_SYMBOL_GPL(ata_port_abort
);
7070 EXPORT_SYMBOL_GPL(ata_port_freeze
);
7071 EXPORT_SYMBOL_GPL(ata_eh_freeze_port
);
7072 EXPORT_SYMBOL_GPL(ata_eh_thaw_port
);
7073 EXPORT_SYMBOL_GPL(ata_eh_qc_complete
);
7074 EXPORT_SYMBOL_GPL(ata_eh_qc_retry
);
7075 EXPORT_SYMBOL_GPL(ata_do_eh
);
7076 EXPORT_SYMBOL_GPL(ata_irq_on
);
7077 EXPORT_SYMBOL_GPL(ata_dummy_irq_on
);
7078 EXPORT_SYMBOL_GPL(ata_irq_ack
);
7079 EXPORT_SYMBOL_GPL(ata_dummy_irq_ack
);
7080 EXPORT_SYMBOL_GPL(ata_dev_try_classify
);
7082 EXPORT_SYMBOL_GPL(ata_cable_40wire
);
7083 EXPORT_SYMBOL_GPL(ata_cable_80wire
);
7084 EXPORT_SYMBOL_GPL(ata_cable_unknown
);
7085 EXPORT_SYMBOL_GPL(ata_cable_sata
);