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/
33 * Standards documents from:
34 * http://www.t13.org (ATA standards, PCI DMA IDE spec)
35 * http://www.t10.org (SCSI MMC - for ATAPI MMC)
36 * http://www.sata-io.org (SATA)
37 * http://www.compactflash.org (CF)
38 * http://www.qic.org (QIC157 - Tape and DSC)
39 * http://www.ce-ata.org (CE-ATA: not supported)
43 #include <linux/kernel.h>
44 #include <linux/module.h>
45 #include <linux/pci.h>
46 #include <linux/init.h>
47 #include <linux/list.h>
49 #include <linux/highmem.h>
50 #include <linux/spinlock.h>
51 #include <linux/blkdev.h>
52 #include <linux/delay.h>
53 #include <linux/timer.h>
54 #include <linux/interrupt.h>
55 #include <linux/completion.h>
56 #include <linux/suspend.h>
57 #include <linux/workqueue.h>
58 #include <linux/jiffies.h>
59 #include <linux/scatterlist.h>
61 #include <scsi/scsi.h>
62 #include <scsi/scsi_cmnd.h>
63 #include <scsi/scsi_host.h>
64 #include <linux/libata.h>
65 #include <asm/semaphore.h>
66 #include <asm/byteorder.h>
67 #include <linux/cdrom.h>
72 /* debounce timing parameters in msecs { interval, duration, timeout } */
73 const unsigned long sata_deb_timing_normal
[] = { 5, 100, 2000 };
74 const unsigned long sata_deb_timing_hotplug
[] = { 25, 500, 2000 };
75 const unsigned long sata_deb_timing_long
[] = { 100, 2000, 5000 };
77 const struct ata_port_operations ata_base_port_ops
= {
78 .irq_clear
= ata_noop_irq_clear
,
81 const struct ata_port_operations sata_port_ops
= {
82 .inherits
= &ata_base_port_ops
,
84 .qc_defer
= ata_std_qc_defer
,
85 .dev_select
= ata_noop_dev_select
,
88 const struct ata_port_operations sata_pmp_port_ops
= {
89 .inherits
= &sata_port_ops
,
92 const struct ata_port_operations ata_sff_port_ops
= {
93 .inherits
= &ata_base_port_ops
,
95 .qc_prep
= ata_qc_prep
,
96 .qc_issue
= ata_qc_issue_prot
,
98 .freeze
= ata_bmdma_freeze
,
99 .thaw
= ata_bmdma_thaw
,
100 .error_handler
= ata_bmdma_error_handler
,
101 .post_internal_cmd
= ata_bmdma_post_internal_cmd
,
103 .dev_select
= ata_std_dev_select
,
104 .check_status
= ata_check_status
,
105 .tf_load
= ata_tf_load
,
106 .tf_read
= ata_tf_read
,
107 .exec_command
= ata_exec_command
,
108 .data_xfer
= ata_data_xfer
,
109 .irq_on
= ata_irq_on
,
111 .port_start
= ata_sff_port_start
,
114 const struct ata_port_operations ata_bmdma_port_ops
= {
115 .inherits
= &ata_sff_port_ops
,
117 .mode_filter
= ata_pci_default_filter
,
119 .bmdma_setup
= ata_bmdma_setup
,
120 .bmdma_start
= ata_bmdma_start
,
121 .bmdma_stop
= ata_bmdma_stop
,
122 .bmdma_status
= ata_bmdma_status
,
123 .irq_clear
= ata_bmdma_irq_clear
,
126 static unsigned int ata_dev_init_params(struct ata_device
*dev
,
127 u16 heads
, u16 sectors
);
128 static unsigned int ata_dev_set_xfermode(struct ata_device
*dev
);
129 static unsigned int ata_dev_set_feature(struct ata_device
*dev
,
130 u8 enable
, u8 feature
);
131 static void ata_dev_xfermask(struct ata_device
*dev
);
132 static unsigned long ata_dev_blacklisted(const struct ata_device
*dev
);
134 unsigned int ata_print_id
= 1;
135 static struct workqueue_struct
*ata_wq
;
137 struct workqueue_struct
*ata_aux_wq
;
139 struct ata_force_param
{
143 unsigned long xfer_mask
;
144 unsigned int horkage_on
;
145 unsigned int horkage_off
;
148 struct ata_force_ent
{
151 struct ata_force_param param
;
154 static struct ata_force_ent
*ata_force_tbl
;
155 static int ata_force_tbl_size
;
157 static char ata_force_param_buf
[PAGE_SIZE
] __initdata
;
158 /* param_buf is thrown away after initialization, disallow read */
159 module_param_string(force
, ata_force_param_buf
, sizeof(ata_force_param_buf
), 0);
160 MODULE_PARM_DESC(force
, "Force ATA configurations including cable type, link speed and transfer mode (see Documentation/kernel-parameters.txt for details)");
162 int atapi_enabled
= 1;
163 module_param(atapi_enabled
, int, 0444);
164 MODULE_PARM_DESC(atapi_enabled
, "Enable discovery of ATAPI devices (0=off, 1=on)");
166 static int atapi_dmadir
= 0;
167 module_param(atapi_dmadir
, int, 0444);
168 MODULE_PARM_DESC(atapi_dmadir
, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");
170 int atapi_passthru16
= 1;
171 module_param(atapi_passthru16
, int, 0444);
172 MODULE_PARM_DESC(atapi_passthru16
, "Enable ATA_16 passthru for ATAPI devices; on by default (0=off, 1=on)");
175 module_param_named(fua
, libata_fua
, int, 0444);
176 MODULE_PARM_DESC(fua
, "FUA support (0=off, 1=on)");
178 static int ata_ignore_hpa
;
179 module_param_named(ignore_hpa
, ata_ignore_hpa
, int, 0644);
180 MODULE_PARM_DESC(ignore_hpa
, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)");
182 static int libata_dma_mask
= ATA_DMA_MASK_ATA
|ATA_DMA_MASK_ATAPI
|ATA_DMA_MASK_CFA
;
183 module_param_named(dma
, libata_dma_mask
, int, 0444);
184 MODULE_PARM_DESC(dma
, "DMA enable/disable (0x1==ATA, 0x2==ATAPI, 0x4==CF)");
186 static int ata_probe_timeout
= ATA_TMOUT_INTERNAL
/ HZ
;
187 module_param(ata_probe_timeout
, int, 0444);
188 MODULE_PARM_DESC(ata_probe_timeout
, "Set ATA probing timeout (seconds)");
190 int libata_noacpi
= 0;
191 module_param_named(noacpi
, libata_noacpi
, int, 0444);
192 MODULE_PARM_DESC(noacpi
, "Disables the use of ACPI in probe/suspend/resume when set");
194 int libata_allow_tpm
= 0;
195 module_param_named(allow_tpm
, libata_allow_tpm
, int, 0444);
196 MODULE_PARM_DESC(allow_tpm
, "Permit the use of TPM commands");
198 MODULE_AUTHOR("Jeff Garzik");
199 MODULE_DESCRIPTION("Library module for ATA devices");
200 MODULE_LICENSE("GPL");
201 MODULE_VERSION(DRV_VERSION
);
205 * ata_force_cbl - force cable type according to libata.force
206 * @ap: ATA port of interest
208 * Force cable type according to libata.force and whine about it.
209 * The last entry which has matching port number is used, so it
210 * can be specified as part of device force parameters. For
211 * example, both "a:40c,1.00:udma4" and "1.00:40c,udma4" have the
217 void ata_force_cbl(struct ata_port
*ap
)
221 for (i
= ata_force_tbl_size
- 1; i
>= 0; i
--) {
222 const struct ata_force_ent
*fe
= &ata_force_tbl
[i
];
224 if (fe
->port
!= -1 && fe
->port
!= ap
->print_id
)
227 if (fe
->param
.cbl
== ATA_CBL_NONE
)
230 ap
->cbl
= fe
->param
.cbl
;
231 ata_port_printk(ap
, KERN_NOTICE
,
232 "FORCE: cable set to %s\n", fe
->param
.name
);
238 * ata_force_spd_limit - force SATA spd limit according to libata.force
239 * @link: ATA link of interest
241 * Force SATA spd limit according to libata.force and whine about
242 * it. When only the port part is specified (e.g. 1:), the limit
243 * applies to all links connected to both the host link and all
244 * fan-out ports connected via PMP. If the device part is
245 * specified as 0 (e.g. 1.00:), it specifies the first fan-out
246 * link not the host link. Device number 15 always points to the
247 * host link whether PMP is attached or not.
252 static void ata_force_spd_limit(struct ata_link
*link
)
256 if (ata_is_host_link(link
))
261 for (i
= ata_force_tbl_size
- 1; i
>= 0; i
--) {
262 const struct ata_force_ent
*fe
= &ata_force_tbl
[i
];
264 if (fe
->port
!= -1 && fe
->port
!= link
->ap
->print_id
)
267 if (fe
->device
!= -1 && fe
->device
!= linkno
)
270 if (!fe
->param
.spd_limit
)
273 link
->hw_sata_spd_limit
= (1 << fe
->param
.spd_limit
) - 1;
274 ata_link_printk(link
, KERN_NOTICE
,
275 "FORCE: PHY spd limit set to %s\n", fe
->param
.name
);
281 * ata_force_xfermask - force xfermask according to libata.force
282 * @dev: ATA device of interest
284 * Force xfer_mask according to libata.force and whine about it.
285 * For consistency with link selection, device number 15 selects
286 * the first device connected to the host link.
291 static void ata_force_xfermask(struct ata_device
*dev
)
293 int devno
= dev
->link
->pmp
+ dev
->devno
;
294 int alt_devno
= devno
;
297 /* allow n.15 for the first device attached to host port */
298 if (ata_is_host_link(dev
->link
) && devno
== 0)
301 for (i
= ata_force_tbl_size
- 1; i
>= 0; i
--) {
302 const struct ata_force_ent
*fe
= &ata_force_tbl
[i
];
303 unsigned long pio_mask
, mwdma_mask
, udma_mask
;
305 if (fe
->port
!= -1 && fe
->port
!= dev
->link
->ap
->print_id
)
308 if (fe
->device
!= -1 && fe
->device
!= devno
&&
309 fe
->device
!= alt_devno
)
312 if (!fe
->param
.xfer_mask
)
315 ata_unpack_xfermask(fe
->param
.xfer_mask
,
316 &pio_mask
, &mwdma_mask
, &udma_mask
);
318 dev
->udma_mask
= udma_mask
;
319 else if (mwdma_mask
) {
321 dev
->mwdma_mask
= mwdma_mask
;
325 dev
->pio_mask
= pio_mask
;
328 ata_dev_printk(dev
, KERN_NOTICE
,
329 "FORCE: xfer_mask set to %s\n", fe
->param
.name
);
335 * ata_force_horkage - force horkage according to libata.force
336 * @dev: ATA device of interest
338 * Force horkage according to libata.force and whine about it.
339 * For consistency with link selection, device number 15 selects
340 * the first device connected to the host link.
345 static void ata_force_horkage(struct ata_device
*dev
)
347 int devno
= dev
->link
->pmp
+ dev
->devno
;
348 int alt_devno
= devno
;
351 /* allow n.15 for the first device attached to host port */
352 if (ata_is_host_link(dev
->link
) && devno
== 0)
355 for (i
= 0; i
< ata_force_tbl_size
; i
++) {
356 const struct ata_force_ent
*fe
= &ata_force_tbl
[i
];
358 if (fe
->port
!= -1 && fe
->port
!= dev
->link
->ap
->print_id
)
361 if (fe
->device
!= -1 && fe
->device
!= devno
&&
362 fe
->device
!= alt_devno
)
365 if (!(~dev
->horkage
& fe
->param
.horkage_on
) &&
366 !(dev
->horkage
& fe
->param
.horkage_off
))
369 dev
->horkage
|= fe
->param
.horkage_on
;
370 dev
->horkage
&= ~fe
->param
.horkage_off
;
372 ata_dev_printk(dev
, KERN_NOTICE
,
373 "FORCE: horkage modified (%s)\n", fe
->param
.name
);
378 * atapi_cmd_type - Determine ATAPI command type from SCSI opcode
379 * @opcode: SCSI opcode
381 * Determine ATAPI command type from @opcode.
387 * ATAPI_{READ|WRITE|READ_CD|PASS_THRU|MISC}
389 int atapi_cmd_type(u8 opcode
)
398 case GPCMD_WRITE_AND_VERIFY_10
:
402 case GPCMD_READ_CD_MSF
:
403 return ATAPI_READ_CD
;
407 if (atapi_passthru16
)
408 return ATAPI_PASS_THRU
;
416 * ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
417 * @tf: Taskfile to convert
418 * @pmp: Port multiplier port
419 * @is_cmd: This FIS is for command
420 * @fis: Buffer into which data will output
422 * Converts a standard ATA taskfile to a Serial ATA
423 * FIS structure (Register - Host to Device).
426 * Inherited from caller.
428 void ata_tf_to_fis(const struct ata_taskfile
*tf
, u8 pmp
, int is_cmd
, u8
*fis
)
430 fis
[0] = 0x27; /* Register - Host to Device FIS */
431 fis
[1] = pmp
& 0xf; /* Port multiplier number*/
433 fis
[1] |= (1 << 7); /* bit 7 indicates Command FIS */
435 fis
[2] = tf
->command
;
436 fis
[3] = tf
->feature
;
443 fis
[8] = tf
->hob_lbal
;
444 fis
[9] = tf
->hob_lbam
;
445 fis
[10] = tf
->hob_lbah
;
446 fis
[11] = tf
->hob_feature
;
449 fis
[13] = tf
->hob_nsect
;
460 * ata_tf_from_fis - Convert SATA FIS to ATA taskfile
461 * @fis: Buffer from which data will be input
462 * @tf: Taskfile to output
464 * Converts a serial ATA FIS structure to a standard ATA taskfile.
467 * Inherited from caller.
470 void ata_tf_from_fis(const u8
*fis
, struct ata_taskfile
*tf
)
472 tf
->command
= fis
[2]; /* status */
473 tf
->feature
= fis
[3]; /* error */
480 tf
->hob_lbal
= fis
[8];
481 tf
->hob_lbam
= fis
[9];
482 tf
->hob_lbah
= fis
[10];
485 tf
->hob_nsect
= fis
[13];
488 static const u8 ata_rw_cmds
[] = {
492 ATA_CMD_READ_MULTI_EXT
,
493 ATA_CMD_WRITE_MULTI_EXT
,
497 ATA_CMD_WRITE_MULTI_FUA_EXT
,
501 ATA_CMD_PIO_READ_EXT
,
502 ATA_CMD_PIO_WRITE_EXT
,
515 ATA_CMD_WRITE_FUA_EXT
519 * ata_rwcmd_protocol - set taskfile r/w commands and protocol
520 * @tf: command to examine and configure
521 * @dev: device tf belongs to
523 * Examine the device configuration and tf->flags to calculate
524 * the proper read/write commands and protocol to use.
529 static int ata_rwcmd_protocol(struct ata_taskfile
*tf
, struct ata_device
*dev
)
533 int index
, fua
, lba48
, write
;
535 fua
= (tf
->flags
& ATA_TFLAG_FUA
) ? 4 : 0;
536 lba48
= (tf
->flags
& ATA_TFLAG_LBA48
) ? 2 : 0;
537 write
= (tf
->flags
& ATA_TFLAG_WRITE
) ? 1 : 0;
539 if (dev
->flags
& ATA_DFLAG_PIO
) {
540 tf
->protocol
= ATA_PROT_PIO
;
541 index
= dev
->multi_count
? 0 : 8;
542 } else if (lba48
&& (dev
->link
->ap
->flags
& ATA_FLAG_PIO_LBA48
)) {
543 /* Unable to use DMA due to host limitation */
544 tf
->protocol
= ATA_PROT_PIO
;
545 index
= dev
->multi_count
? 0 : 8;
547 tf
->protocol
= ATA_PROT_DMA
;
551 cmd
= ata_rw_cmds
[index
+ fua
+ lba48
+ write
];
560 * ata_tf_read_block - Read block address from ATA taskfile
561 * @tf: ATA taskfile of interest
562 * @dev: ATA device @tf belongs to
567 * Read block address from @tf. This function can handle all
568 * three address formats - LBA, LBA48 and CHS. tf->protocol and
569 * flags select the address format to use.
572 * Block address read from @tf.
574 u64
ata_tf_read_block(struct ata_taskfile
*tf
, struct ata_device
*dev
)
578 if (tf
->flags
& ATA_TFLAG_LBA
) {
579 if (tf
->flags
& ATA_TFLAG_LBA48
) {
580 block
|= (u64
)tf
->hob_lbah
<< 40;
581 block
|= (u64
)tf
->hob_lbam
<< 32;
582 block
|= tf
->hob_lbal
<< 24;
584 block
|= (tf
->device
& 0xf) << 24;
586 block
|= tf
->lbah
<< 16;
587 block
|= tf
->lbam
<< 8;
592 cyl
= tf
->lbam
| (tf
->lbah
<< 8);
593 head
= tf
->device
& 0xf;
596 block
= (cyl
* dev
->heads
+ head
) * dev
->sectors
+ sect
;
603 * ata_build_rw_tf - Build ATA taskfile for given read/write request
604 * @tf: Target ATA taskfile
605 * @dev: ATA device @tf belongs to
606 * @block: Block address
607 * @n_block: Number of blocks
608 * @tf_flags: RW/FUA etc...
614 * Build ATA taskfile @tf for read/write request described by
615 * @block, @n_block, @tf_flags and @tag on @dev.
619 * 0 on success, -ERANGE if the request is too large for @dev,
620 * -EINVAL if the request is invalid.
622 int ata_build_rw_tf(struct ata_taskfile
*tf
, struct ata_device
*dev
,
623 u64 block
, u32 n_block
, unsigned int tf_flags
,
626 tf
->flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
627 tf
->flags
|= tf_flags
;
629 if (ata_ncq_enabled(dev
) && likely(tag
!= ATA_TAG_INTERNAL
)) {
631 if (!lba_48_ok(block
, n_block
))
634 tf
->protocol
= ATA_PROT_NCQ
;
635 tf
->flags
|= ATA_TFLAG_LBA
| ATA_TFLAG_LBA48
;
637 if (tf
->flags
& ATA_TFLAG_WRITE
)
638 tf
->command
= ATA_CMD_FPDMA_WRITE
;
640 tf
->command
= ATA_CMD_FPDMA_READ
;
642 tf
->nsect
= tag
<< 3;
643 tf
->hob_feature
= (n_block
>> 8) & 0xff;
644 tf
->feature
= n_block
& 0xff;
646 tf
->hob_lbah
= (block
>> 40) & 0xff;
647 tf
->hob_lbam
= (block
>> 32) & 0xff;
648 tf
->hob_lbal
= (block
>> 24) & 0xff;
649 tf
->lbah
= (block
>> 16) & 0xff;
650 tf
->lbam
= (block
>> 8) & 0xff;
651 tf
->lbal
= block
& 0xff;
654 if (tf
->flags
& ATA_TFLAG_FUA
)
655 tf
->device
|= 1 << 7;
656 } else if (dev
->flags
& ATA_DFLAG_LBA
) {
657 tf
->flags
|= ATA_TFLAG_LBA
;
659 if (lba_28_ok(block
, n_block
)) {
661 tf
->device
|= (block
>> 24) & 0xf;
662 } else if (lba_48_ok(block
, n_block
)) {
663 if (!(dev
->flags
& ATA_DFLAG_LBA48
))
667 tf
->flags
|= ATA_TFLAG_LBA48
;
669 tf
->hob_nsect
= (n_block
>> 8) & 0xff;
671 tf
->hob_lbah
= (block
>> 40) & 0xff;
672 tf
->hob_lbam
= (block
>> 32) & 0xff;
673 tf
->hob_lbal
= (block
>> 24) & 0xff;
675 /* request too large even for LBA48 */
678 if (unlikely(ata_rwcmd_protocol(tf
, dev
) < 0))
681 tf
->nsect
= n_block
& 0xff;
683 tf
->lbah
= (block
>> 16) & 0xff;
684 tf
->lbam
= (block
>> 8) & 0xff;
685 tf
->lbal
= block
& 0xff;
687 tf
->device
|= ATA_LBA
;
690 u32 sect
, head
, cyl
, track
;
692 /* The request -may- be too large for CHS addressing. */
693 if (!lba_28_ok(block
, n_block
))
696 if (unlikely(ata_rwcmd_protocol(tf
, dev
) < 0))
699 /* Convert LBA to CHS */
700 track
= (u32
)block
/ dev
->sectors
;
701 cyl
= track
/ dev
->heads
;
702 head
= track
% dev
->heads
;
703 sect
= (u32
)block
% dev
->sectors
+ 1;
705 DPRINTK("block %u track %u cyl %u head %u sect %u\n",
706 (u32
)block
, track
, cyl
, head
, sect
);
708 /* Check whether the converted CHS can fit.
712 if ((cyl
>> 16) || (head
>> 4) || (sect
>> 8) || (!sect
))
715 tf
->nsect
= n_block
& 0xff; /* Sector count 0 means 256 sectors */
726 * ata_pack_xfermask - Pack pio, mwdma and udma masks into xfer_mask
727 * @pio_mask: pio_mask
728 * @mwdma_mask: mwdma_mask
729 * @udma_mask: udma_mask
731 * Pack @pio_mask, @mwdma_mask and @udma_mask into a single
732 * unsigned int xfer_mask.
740 unsigned long ata_pack_xfermask(unsigned long pio_mask
,
741 unsigned long mwdma_mask
,
742 unsigned long udma_mask
)
744 return ((pio_mask
<< ATA_SHIFT_PIO
) & ATA_MASK_PIO
) |
745 ((mwdma_mask
<< ATA_SHIFT_MWDMA
) & ATA_MASK_MWDMA
) |
746 ((udma_mask
<< ATA_SHIFT_UDMA
) & ATA_MASK_UDMA
);
750 * ata_unpack_xfermask - Unpack xfer_mask into pio, mwdma and udma masks
751 * @xfer_mask: xfer_mask to unpack
752 * @pio_mask: resulting pio_mask
753 * @mwdma_mask: resulting mwdma_mask
754 * @udma_mask: resulting udma_mask
756 * Unpack @xfer_mask into @pio_mask, @mwdma_mask and @udma_mask.
757 * Any NULL distination masks will be ignored.
759 void ata_unpack_xfermask(unsigned long xfer_mask
, unsigned long *pio_mask
,
760 unsigned long *mwdma_mask
, unsigned long *udma_mask
)
763 *pio_mask
= (xfer_mask
& ATA_MASK_PIO
) >> ATA_SHIFT_PIO
;
765 *mwdma_mask
= (xfer_mask
& ATA_MASK_MWDMA
) >> ATA_SHIFT_MWDMA
;
767 *udma_mask
= (xfer_mask
& ATA_MASK_UDMA
) >> ATA_SHIFT_UDMA
;
770 static const struct ata_xfer_ent
{
774 { ATA_SHIFT_PIO
, ATA_NR_PIO_MODES
, XFER_PIO_0
},
775 { ATA_SHIFT_MWDMA
, ATA_NR_MWDMA_MODES
, XFER_MW_DMA_0
},
776 { ATA_SHIFT_UDMA
, ATA_NR_UDMA_MODES
, XFER_UDMA_0
},
781 * ata_xfer_mask2mode - Find matching XFER_* for the given xfer_mask
782 * @xfer_mask: xfer_mask of interest
784 * Return matching XFER_* value for @xfer_mask. Only the highest
785 * bit of @xfer_mask is considered.
791 * Matching XFER_* value, 0xff if no match found.
793 u8
ata_xfer_mask2mode(unsigned long xfer_mask
)
795 int highbit
= fls(xfer_mask
) - 1;
796 const struct ata_xfer_ent
*ent
;
798 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
799 if (highbit
>= ent
->shift
&& highbit
< ent
->shift
+ ent
->bits
)
800 return ent
->base
+ highbit
- ent
->shift
;
805 * ata_xfer_mode2mask - Find matching xfer_mask for XFER_*
806 * @xfer_mode: XFER_* of interest
808 * Return matching xfer_mask for @xfer_mode.
814 * Matching xfer_mask, 0 if no match found.
816 unsigned long ata_xfer_mode2mask(u8 xfer_mode
)
818 const struct ata_xfer_ent
*ent
;
820 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
821 if (xfer_mode
>= ent
->base
&& xfer_mode
< ent
->base
+ ent
->bits
)
822 return ((2 << (ent
->shift
+ xfer_mode
- ent
->base
)) - 1)
823 & ~((1 << ent
->shift
) - 1);
828 * ata_xfer_mode2shift - Find matching xfer_shift for XFER_*
829 * @xfer_mode: XFER_* of interest
831 * Return matching xfer_shift for @xfer_mode.
837 * Matching xfer_shift, -1 if no match found.
839 int ata_xfer_mode2shift(unsigned long xfer_mode
)
841 const struct ata_xfer_ent
*ent
;
843 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
844 if (xfer_mode
>= ent
->base
&& xfer_mode
< ent
->base
+ ent
->bits
)
850 * ata_mode_string - convert xfer_mask to string
851 * @xfer_mask: mask of bits supported; only highest bit counts.
853 * Determine string which represents the highest speed
854 * (highest bit in @modemask).
860 * Constant C string representing highest speed listed in
861 * @mode_mask, or the constant C string "<n/a>".
863 const char *ata_mode_string(unsigned long xfer_mask
)
865 static const char * const xfer_mode_str
[] = {
889 highbit
= fls(xfer_mask
) - 1;
890 if (highbit
>= 0 && highbit
< ARRAY_SIZE(xfer_mode_str
))
891 return xfer_mode_str
[highbit
];
895 static const char *sata_spd_string(unsigned int spd
)
897 static const char * const spd_str
[] = {
902 if (spd
== 0 || (spd
- 1) >= ARRAY_SIZE(spd_str
))
904 return spd_str
[spd
- 1];
907 void ata_dev_disable(struct ata_device
*dev
)
909 if (ata_dev_enabled(dev
)) {
910 if (ata_msg_drv(dev
->link
->ap
))
911 ata_dev_printk(dev
, KERN_WARNING
, "disabled\n");
912 ata_acpi_on_disable(dev
);
913 ata_down_xfermask_limit(dev
, ATA_DNXFER_FORCE_PIO0
|
919 static int ata_dev_set_dipm(struct ata_device
*dev
, enum link_pm policy
)
921 struct ata_link
*link
= dev
->link
;
922 struct ata_port
*ap
= link
->ap
;
924 unsigned int err_mask
;
928 * disallow DIPM for drivers which haven't set
929 * ATA_FLAG_IPM. This is because when DIPM is enabled,
930 * phy ready will be set in the interrupt status on
931 * state changes, which will cause some drivers to
932 * think there are errors - additionally drivers will
933 * need to disable hot plug.
935 if (!(ap
->flags
& ATA_FLAG_IPM
) || !ata_dev_enabled(dev
)) {
936 ap
->pm_policy
= NOT_AVAILABLE
;
941 * For DIPM, we will only enable it for the
944 * Why? Because Disks are too stupid to know that
945 * If the host rejects a request to go to SLUMBER
946 * they should retry at PARTIAL, and instead it
947 * just would give up. So, for medium_power to
948 * work at all, we need to only allow HIPM.
950 rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
956 /* no restrictions on IPM transitions */
957 scontrol
&= ~(0x3 << 8);
958 rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
);
963 if (dev
->flags
& ATA_DFLAG_DIPM
)
964 err_mask
= ata_dev_set_feature(dev
,
965 SETFEATURES_SATA_ENABLE
, SATA_DIPM
);
968 /* allow IPM to PARTIAL */
969 scontrol
&= ~(0x1 << 8);
970 scontrol
|= (0x2 << 8);
971 rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
);
976 * we don't have to disable DIPM since IPM flags
977 * disallow transitions to SLUMBER, which effectively
978 * disable DIPM if it does not support PARTIAL
982 case MAX_PERFORMANCE
:
983 /* disable all IPM transitions */
984 scontrol
|= (0x3 << 8);
985 rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
);
990 * we don't have to disable DIPM since IPM flags
991 * disallow all transitions which effectively
992 * disable DIPM anyway.
997 /* FIXME: handle SET FEATURES failure */
1004 * ata_dev_enable_pm - enable SATA interface power management
1005 * @dev: device to enable power management
1006 * @policy: the link power management policy
1008 * Enable SATA Interface power management. This will enable
1009 * Device Interface Power Management (DIPM) for min_power
1010 * policy, and then call driver specific callbacks for
1011 * enabling Host Initiated Power management.
1014 * Returns: -EINVAL if IPM is not supported, 0 otherwise.
1016 void ata_dev_enable_pm(struct ata_device
*dev
, enum link_pm policy
)
1019 struct ata_port
*ap
= dev
->link
->ap
;
1021 /* set HIPM first, then DIPM */
1022 if (ap
->ops
->enable_pm
)
1023 rc
= ap
->ops
->enable_pm(ap
, policy
);
1026 rc
= ata_dev_set_dipm(dev
, policy
);
1030 ap
->pm_policy
= MAX_PERFORMANCE
;
1032 ap
->pm_policy
= policy
;
1033 return /* rc */; /* hopefully we can use 'rc' eventually */
1038 * ata_dev_disable_pm - disable SATA interface power management
1039 * @dev: device to disable power management
1041 * Disable SATA Interface power management. This will disable
1042 * Device Interface Power Management (DIPM) without changing
1043 * policy, call driver specific callbacks for disabling Host
1044 * Initiated Power management.
1049 static void ata_dev_disable_pm(struct ata_device
*dev
)
1051 struct ata_port
*ap
= dev
->link
->ap
;
1053 ata_dev_set_dipm(dev
, MAX_PERFORMANCE
);
1054 if (ap
->ops
->disable_pm
)
1055 ap
->ops
->disable_pm(ap
);
1057 #endif /* CONFIG_PM */
1059 void ata_lpm_schedule(struct ata_port
*ap
, enum link_pm policy
)
1061 ap
->pm_policy
= policy
;
1062 ap
->link
.eh_info
.action
|= ATA_EH_LPM
;
1063 ap
->link
.eh_info
.flags
|= ATA_EHI_NO_AUTOPSY
;
1064 ata_port_schedule_eh(ap
);
1068 static void ata_lpm_enable(struct ata_host
*host
)
1070 struct ata_link
*link
;
1071 struct ata_port
*ap
;
1072 struct ata_device
*dev
;
1075 for (i
= 0; i
< host
->n_ports
; i
++) {
1076 ap
= host
->ports
[i
];
1077 ata_port_for_each_link(link
, ap
) {
1078 ata_link_for_each_dev(dev
, link
)
1079 ata_dev_disable_pm(dev
);
1084 static void ata_lpm_disable(struct ata_host
*host
)
1088 for (i
= 0; i
< host
->n_ports
; i
++) {
1089 struct ata_port
*ap
= host
->ports
[i
];
1090 ata_lpm_schedule(ap
, ap
->pm_policy
);
1093 #endif /* CONFIG_PM */
1097 * ata_devchk - PATA device presence detection
1098 * @ap: ATA channel to examine
1099 * @device: Device to examine (starting at zero)
1101 * This technique was originally described in
1102 * Hale Landis's ATADRVR (www.ata-atapi.com), and
1103 * later found its way into the ATA/ATAPI spec.
1105 * Write a pattern to the ATA shadow registers,
1106 * and if a device is present, it will respond by
1107 * correctly storing and echoing back the
1108 * ATA shadow register contents.
1114 static unsigned int ata_devchk(struct ata_port
*ap
, unsigned int device
)
1116 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
1119 ap
->ops
->dev_select(ap
, device
);
1121 iowrite8(0x55, ioaddr
->nsect_addr
);
1122 iowrite8(0xaa, ioaddr
->lbal_addr
);
1124 iowrite8(0xaa, ioaddr
->nsect_addr
);
1125 iowrite8(0x55, ioaddr
->lbal_addr
);
1127 iowrite8(0x55, ioaddr
->nsect_addr
);
1128 iowrite8(0xaa, ioaddr
->lbal_addr
);
1130 nsect
= ioread8(ioaddr
->nsect_addr
);
1131 lbal
= ioread8(ioaddr
->lbal_addr
);
1133 if ((nsect
== 0x55) && (lbal
== 0xaa))
1134 return 1; /* we found a device */
1136 return 0; /* nothing found */
1140 * ata_dev_classify - determine device type based on ATA-spec signature
1141 * @tf: ATA taskfile register set for device to be identified
1143 * Determine from taskfile register contents whether a device is
1144 * ATA or ATAPI, as per "Signature and persistence" section
1145 * of ATA/PI spec (volume 1, sect 5.14).
1151 * Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP or
1152 * %ATA_DEV_UNKNOWN the event of failure.
1154 unsigned int ata_dev_classify(const struct ata_taskfile
*tf
)
1156 /* Apple's open source Darwin code hints that some devices only
1157 * put a proper signature into the LBA mid/high registers,
1158 * So, we only check those. It's sufficient for uniqueness.
1160 * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate
1161 * signatures for ATA and ATAPI devices attached on SerialATA,
1162 * 0x3c/0xc3 and 0x69/0x96 respectively. However, SerialATA
1163 * spec has never mentioned about using different signatures
1164 * for ATA/ATAPI devices. Then, Serial ATA II: Port
1165 * Multiplier specification began to use 0x69/0x96 to identify
1166 * port multpliers and 0x3c/0xc3 to identify SEMB device.
1167 * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and
1168 * 0x69/0x96 shortly and described them as reserved for
1171 * We follow the current spec and consider that 0x69/0x96
1172 * identifies a port multiplier and 0x3c/0xc3 a SEMB device.
1174 if ((tf
->lbam
== 0) && (tf
->lbah
== 0)) {
1175 DPRINTK("found ATA device by sig\n");
1179 if ((tf
->lbam
== 0x14) && (tf
->lbah
== 0xeb)) {
1180 DPRINTK("found ATAPI device by sig\n");
1181 return ATA_DEV_ATAPI
;
1184 if ((tf
->lbam
== 0x69) && (tf
->lbah
== 0x96)) {
1185 DPRINTK("found PMP device by sig\n");
1189 if ((tf
->lbam
== 0x3c) && (tf
->lbah
== 0xc3)) {
1190 printk(KERN_INFO
"ata: SEMB device ignored\n");
1191 return ATA_DEV_SEMB_UNSUP
; /* not yet */
1194 DPRINTK("unknown device\n");
1195 return ATA_DEV_UNKNOWN
;
1199 * ata_dev_try_classify - Parse returned ATA device signature
1200 * @dev: ATA device to classify (starting at zero)
1201 * @present: device seems present
1202 * @r_err: Value of error register on completion
1204 * After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
1205 * an ATA/ATAPI-defined set of values is placed in the ATA
1206 * shadow registers, indicating the results of device detection
1209 * Select the ATA device, and read the values from the ATA shadow
1210 * registers. Then parse according to the Error register value,
1211 * and the spec-defined values examined by ata_dev_classify().
1217 * Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
1219 unsigned int ata_dev_try_classify(struct ata_device
*dev
, int present
,
1222 struct ata_port
*ap
= dev
->link
->ap
;
1223 struct ata_taskfile tf
;
1227 ap
->ops
->dev_select(ap
, dev
->devno
);
1229 memset(&tf
, 0, sizeof(tf
));
1231 ap
->ops
->tf_read(ap
, &tf
);
1236 /* see if device passed diags: continue and warn later */
1238 /* diagnostic fail : do nothing _YET_ */
1239 dev
->horkage
|= ATA_HORKAGE_DIAGNOSTIC
;
1242 else if ((dev
->devno
== 0) && (err
== 0x81))
1245 return ATA_DEV_NONE
;
1247 /* determine if device is ATA or ATAPI */
1248 class = ata_dev_classify(&tf
);
1250 if (class == ATA_DEV_UNKNOWN
) {
1251 /* If the device failed diagnostic, it's likely to
1252 * have reported incorrect device signature too.
1253 * Assume ATA device if the device seems present but
1254 * device signature is invalid with diagnostic
1257 if (present
&& (dev
->horkage
& ATA_HORKAGE_DIAGNOSTIC
))
1258 class = ATA_DEV_ATA
;
1260 class = ATA_DEV_NONE
;
1261 } else if ((class == ATA_DEV_ATA
) && (ata_chk_status(ap
) == 0))
1262 class = ATA_DEV_NONE
;
1268 * ata_id_string - Convert IDENTIFY DEVICE page into string
1269 * @id: IDENTIFY DEVICE results we will examine
1270 * @s: string into which data is output
1271 * @ofs: offset into identify device page
1272 * @len: length of string to return. must be an even number.
1274 * The strings in the IDENTIFY DEVICE page are broken up into
1275 * 16-bit chunks. Run through the string, and output each
1276 * 8-bit chunk linearly, regardless of platform.
1282 void ata_id_string(const u16
*id
, unsigned char *s
,
1283 unsigned int ofs
, unsigned int len
)
1302 * ata_id_c_string - Convert IDENTIFY DEVICE page into C string
1303 * @id: IDENTIFY DEVICE results we will examine
1304 * @s: string into which data is output
1305 * @ofs: offset into identify device page
1306 * @len: length of string to return. must be an odd number.
1308 * This function is identical to ata_id_string except that it
1309 * trims trailing spaces and terminates the resulting string with
1310 * null. @len must be actual maximum length (even number) + 1.
1315 void ata_id_c_string(const u16
*id
, unsigned char *s
,
1316 unsigned int ofs
, unsigned int len
)
1320 WARN_ON(!(len
& 1));
1322 ata_id_string(id
, s
, ofs
, len
- 1);
1324 p
= s
+ strnlen(s
, len
- 1);
1325 while (p
> s
&& p
[-1] == ' ')
1330 static u64
ata_id_n_sectors(const u16
*id
)
1332 if (ata_id_has_lba(id
)) {
1333 if (ata_id_has_lba48(id
))
1334 return ata_id_u64(id
, 100);
1336 return ata_id_u32(id
, 60);
1338 if (ata_id_current_chs_valid(id
))
1339 return ata_id_u32(id
, 57);
1341 return id
[1] * id
[3] * id
[6];
1345 static u64
ata_tf_to_lba48(struct ata_taskfile
*tf
)
1349 sectors
|= ((u64
)(tf
->hob_lbah
& 0xff)) << 40;
1350 sectors
|= ((u64
)(tf
->hob_lbam
& 0xff)) << 32;
1351 sectors
|= (tf
->hob_lbal
& 0xff) << 24;
1352 sectors
|= (tf
->lbah
& 0xff) << 16;
1353 sectors
|= (tf
->lbam
& 0xff) << 8;
1354 sectors
|= (tf
->lbal
& 0xff);
1359 static u64
ata_tf_to_lba(struct ata_taskfile
*tf
)
1363 sectors
|= (tf
->device
& 0x0f) << 24;
1364 sectors
|= (tf
->lbah
& 0xff) << 16;
1365 sectors
|= (tf
->lbam
& 0xff) << 8;
1366 sectors
|= (tf
->lbal
& 0xff);
1372 * ata_read_native_max_address - Read native max address
1373 * @dev: target device
1374 * @max_sectors: out parameter for the result native max address
1376 * Perform an LBA48 or LBA28 native size query upon the device in
1380 * 0 on success, -EACCES if command is aborted by the drive.
1381 * -EIO on other errors.
1383 static int ata_read_native_max_address(struct ata_device
*dev
, u64
*max_sectors
)
1385 unsigned int err_mask
;
1386 struct ata_taskfile tf
;
1387 int lba48
= ata_id_has_lba48(dev
->id
);
1389 ata_tf_init(dev
, &tf
);
1391 /* always clear all address registers */
1392 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_ISADDR
;
1395 tf
.command
= ATA_CMD_READ_NATIVE_MAX_EXT
;
1396 tf
.flags
|= ATA_TFLAG_LBA48
;
1398 tf
.command
= ATA_CMD_READ_NATIVE_MAX
;
1400 tf
.protocol
|= ATA_PROT_NODATA
;
1401 tf
.device
|= ATA_LBA
;
1403 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
1405 ata_dev_printk(dev
, KERN_WARNING
, "failed to read native "
1406 "max address (err_mask=0x%x)\n", err_mask
);
1407 if (err_mask
== AC_ERR_DEV
&& (tf
.feature
& ATA_ABORTED
))
1413 *max_sectors
= ata_tf_to_lba48(&tf
);
1415 *max_sectors
= ata_tf_to_lba(&tf
);
1416 if (dev
->horkage
& ATA_HORKAGE_HPA_SIZE
)
1422 * ata_set_max_sectors - Set max sectors
1423 * @dev: target device
1424 * @new_sectors: new max sectors value to set for the device
1426 * Set max sectors of @dev to @new_sectors.
1429 * 0 on success, -EACCES if command is aborted or denied (due to
1430 * previous non-volatile SET_MAX) by the drive. -EIO on other
1433 static int ata_set_max_sectors(struct ata_device
*dev
, u64 new_sectors
)
1435 unsigned int err_mask
;
1436 struct ata_taskfile tf
;
1437 int lba48
= ata_id_has_lba48(dev
->id
);
1441 ata_tf_init(dev
, &tf
);
1443 tf
.flags
|= ATA_TFLAG_DEVICE
| ATA_TFLAG_ISADDR
;
1446 tf
.command
= ATA_CMD_SET_MAX_EXT
;
1447 tf
.flags
|= ATA_TFLAG_LBA48
;
1449 tf
.hob_lbal
= (new_sectors
>> 24) & 0xff;
1450 tf
.hob_lbam
= (new_sectors
>> 32) & 0xff;
1451 tf
.hob_lbah
= (new_sectors
>> 40) & 0xff;
1453 tf
.command
= ATA_CMD_SET_MAX
;
1455 tf
.device
|= (new_sectors
>> 24) & 0xf;
1458 tf
.protocol
|= ATA_PROT_NODATA
;
1459 tf
.device
|= ATA_LBA
;
1461 tf
.lbal
= (new_sectors
>> 0) & 0xff;
1462 tf
.lbam
= (new_sectors
>> 8) & 0xff;
1463 tf
.lbah
= (new_sectors
>> 16) & 0xff;
1465 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
1467 ata_dev_printk(dev
, KERN_WARNING
, "failed to set "
1468 "max address (err_mask=0x%x)\n", err_mask
);
1469 if (err_mask
== AC_ERR_DEV
&&
1470 (tf
.feature
& (ATA_ABORTED
| ATA_IDNF
)))
1479 * ata_hpa_resize - Resize a device with an HPA set
1480 * @dev: Device to resize
1482 * Read the size of an LBA28 or LBA48 disk with HPA features and resize
1483 * it if required to the full size of the media. The caller must check
1484 * the drive has the HPA feature set enabled.
1487 * 0 on success, -errno on failure.
1489 static int ata_hpa_resize(struct ata_device
*dev
)
1491 struct ata_eh_context
*ehc
= &dev
->link
->eh_context
;
1492 int print_info
= ehc
->i
.flags
& ATA_EHI_PRINTINFO
;
1493 u64 sectors
= ata_id_n_sectors(dev
->id
);
1497 /* do we need to do it? */
1498 if (dev
->class != ATA_DEV_ATA
||
1499 !ata_id_has_lba(dev
->id
) || !ata_id_hpa_enabled(dev
->id
) ||
1500 (dev
->horkage
& ATA_HORKAGE_BROKEN_HPA
))
1503 /* read native max address */
1504 rc
= ata_read_native_max_address(dev
, &native_sectors
);
1506 /* If device aborted the command or HPA isn't going to
1507 * be unlocked, skip HPA resizing.
1509 if (rc
== -EACCES
|| !ata_ignore_hpa
) {
1510 ata_dev_printk(dev
, KERN_WARNING
, "HPA support seems "
1511 "broken, skipping HPA handling\n");
1512 dev
->horkage
|= ATA_HORKAGE_BROKEN_HPA
;
1514 /* we can continue if device aborted the command */
1522 /* nothing to do? */
1523 if (native_sectors
<= sectors
|| !ata_ignore_hpa
) {
1524 if (!print_info
|| native_sectors
== sectors
)
1527 if (native_sectors
> sectors
)
1528 ata_dev_printk(dev
, KERN_INFO
,
1529 "HPA detected: current %llu, native %llu\n",
1530 (unsigned long long)sectors
,
1531 (unsigned long long)native_sectors
);
1532 else if (native_sectors
< sectors
)
1533 ata_dev_printk(dev
, KERN_WARNING
,
1534 "native sectors (%llu) is smaller than "
1536 (unsigned long long)native_sectors
,
1537 (unsigned long long)sectors
);
1541 /* let's unlock HPA */
1542 rc
= ata_set_max_sectors(dev
, native_sectors
);
1543 if (rc
== -EACCES
) {
1544 /* if device aborted the command, skip HPA resizing */
1545 ata_dev_printk(dev
, KERN_WARNING
, "device aborted resize "
1546 "(%llu -> %llu), skipping HPA handling\n",
1547 (unsigned long long)sectors
,
1548 (unsigned long long)native_sectors
);
1549 dev
->horkage
|= ATA_HORKAGE_BROKEN_HPA
;
1554 /* re-read IDENTIFY data */
1555 rc
= ata_dev_reread_id(dev
, 0);
1557 ata_dev_printk(dev
, KERN_ERR
, "failed to re-read IDENTIFY "
1558 "data after HPA resizing\n");
1563 u64 new_sectors
= ata_id_n_sectors(dev
->id
);
1564 ata_dev_printk(dev
, KERN_INFO
,
1565 "HPA unlocked: %llu -> %llu, native %llu\n",
1566 (unsigned long long)sectors
,
1567 (unsigned long long)new_sectors
,
1568 (unsigned long long)native_sectors
);
1575 * ata_noop_dev_select - Select device 0/1 on ATA bus
1576 * @ap: ATA channel to manipulate
1577 * @device: ATA device (numbered from zero) to select
1579 * This function performs no actual function.
1581 * May be used as the dev_select() entry in ata_port_operations.
1586 void ata_noop_dev_select(struct ata_port
*ap
, unsigned int device
)
1592 * ata_std_dev_select - Select device 0/1 on ATA bus
1593 * @ap: ATA channel to manipulate
1594 * @device: ATA device (numbered from zero) to select
1596 * Use the method defined in the ATA specification to
1597 * make either device 0, or device 1, active on the
1598 * ATA channel. Works with both PIO and MMIO.
1600 * May be used as the dev_select() entry in ata_port_operations.
1606 void ata_std_dev_select(struct ata_port
*ap
, unsigned int device
)
1611 tmp
= ATA_DEVICE_OBS
;
1613 tmp
= ATA_DEVICE_OBS
| ATA_DEV1
;
1615 iowrite8(tmp
, ap
->ioaddr
.device_addr
);
1616 ata_pause(ap
); /* needed; also flushes, for mmio */
1620 * ata_dev_select - Select device 0/1 on ATA bus
1621 * @ap: ATA channel to manipulate
1622 * @device: ATA device (numbered from zero) to select
1623 * @wait: non-zero to wait for Status register BSY bit to clear
1624 * @can_sleep: non-zero if context allows sleeping
1626 * Use the method defined in the ATA specification to
1627 * make either device 0, or device 1, active on the
1630 * This is a high-level version of ata_std_dev_select(),
1631 * which additionally provides the services of inserting
1632 * the proper pauses and status polling, where needed.
1638 void ata_dev_select(struct ata_port
*ap
, unsigned int device
,
1639 unsigned int wait
, unsigned int can_sleep
)
1641 if (ata_msg_probe(ap
))
1642 ata_port_printk(ap
, KERN_INFO
, "ata_dev_select: ENTER, "
1643 "device %u, wait %u\n", device
, wait
);
1648 ap
->ops
->dev_select(ap
, device
);
1651 if (can_sleep
&& ap
->link
.device
[device
].class == ATA_DEV_ATAPI
)
1658 * ata_dump_id - IDENTIFY DEVICE info debugging output
1659 * @id: IDENTIFY DEVICE page to dump
1661 * Dump selected 16-bit words from the given IDENTIFY DEVICE
1668 static inline void ata_dump_id(const u16
*id
)
1670 DPRINTK("49==0x%04x "
1680 DPRINTK("80==0x%04x "
1690 DPRINTK("88==0x%04x "
1697 * ata_id_xfermask - Compute xfermask from the given IDENTIFY data
1698 * @id: IDENTIFY data to compute xfer mask from
1700 * Compute the xfermask for this device. This is not as trivial
1701 * as it seems if we must consider early devices correctly.
1703 * FIXME: pre IDE drive timing (do we care ?).
1711 unsigned long ata_id_xfermask(const u16
*id
)
1713 unsigned long pio_mask
, mwdma_mask
, udma_mask
;
1715 /* Usual case. Word 53 indicates word 64 is valid */
1716 if (id
[ATA_ID_FIELD_VALID
] & (1 << 1)) {
1717 pio_mask
= id
[ATA_ID_PIO_MODES
] & 0x03;
1721 /* If word 64 isn't valid then Word 51 high byte holds
1722 * the PIO timing number for the maximum. Turn it into
1725 u8 mode
= (id
[ATA_ID_OLD_PIO_MODES
] >> 8) & 0xFF;
1726 if (mode
< 5) /* Valid PIO range */
1727 pio_mask
= (2 << mode
) - 1;
1731 /* But wait.. there's more. Design your standards by
1732 * committee and you too can get a free iordy field to
1733 * process. However its the speeds not the modes that
1734 * are supported... Note drivers using the timing API
1735 * will get this right anyway
1739 mwdma_mask
= id
[ATA_ID_MWDMA_MODES
] & 0x07;
1741 if (ata_id_is_cfa(id
)) {
1743 * Process compact flash extended modes
1745 int pio
= id
[163] & 0x7;
1746 int dma
= (id
[163] >> 3) & 7;
1749 pio_mask
|= (1 << 5);
1751 pio_mask
|= (1 << 6);
1753 mwdma_mask
|= (1 << 3);
1755 mwdma_mask
|= (1 << 4);
1759 if (id
[ATA_ID_FIELD_VALID
] & (1 << 2))
1760 udma_mask
= id
[ATA_ID_UDMA_MODES
] & 0xff;
1762 return ata_pack_xfermask(pio_mask
, mwdma_mask
, udma_mask
);
1766 * ata_pio_queue_task - Queue port_task
1767 * @ap: The ata_port to queue port_task for
1768 * @fn: workqueue function to be scheduled
1769 * @data: data for @fn to use
1770 * @delay: delay time for workqueue function
1772 * Schedule @fn(@data) for execution after @delay jiffies using
1773 * port_task. There is one port_task per port and it's the
1774 * user(low level driver)'s responsibility to make sure that only
1775 * one task is active at any given time.
1777 * libata core layer takes care of synchronization between
1778 * port_task and EH. ata_pio_queue_task() may be ignored for EH
1782 * Inherited from caller.
1784 static void ata_pio_queue_task(struct ata_port
*ap
, void *data
,
1785 unsigned long delay
)
1787 ap
->port_task_data
= data
;
1789 /* may fail if ata_port_flush_task() in progress */
1790 queue_delayed_work(ata_wq
, &ap
->port_task
, delay
);
1794 * ata_port_flush_task - Flush port_task
1795 * @ap: The ata_port to flush port_task for
1797 * After this function completes, port_task is guranteed not to
1798 * be running or scheduled.
1801 * Kernel thread context (may sleep)
1803 void ata_port_flush_task(struct ata_port
*ap
)
1807 cancel_rearming_delayed_work(&ap
->port_task
);
1809 if (ata_msg_ctl(ap
))
1810 ata_port_printk(ap
, KERN_DEBUG
, "%s: EXIT\n", __func__
);
1813 static void ata_qc_complete_internal(struct ata_queued_cmd
*qc
)
1815 struct completion
*waiting
= qc
->private_data
;
1821 * ata_exec_internal_sg - execute libata internal command
1822 * @dev: Device to which the command is sent
1823 * @tf: Taskfile registers for the command and the result
1824 * @cdb: CDB for packet command
1825 * @dma_dir: Data tranfer direction of the command
1826 * @sgl: sg list for the data buffer of the command
1827 * @n_elem: Number of sg entries
1828 * @timeout: Timeout in msecs (0 for default)
1830 * Executes libata internal command with timeout. @tf contains
1831 * command on entry and result on return. Timeout and error
1832 * conditions are reported via return value. No recovery action
1833 * is taken after a command times out. It's caller's duty to
1834 * clean up after timeout.
1837 * None. Should be called with kernel context, might sleep.
1840 * Zero on success, AC_ERR_* mask on failure
1842 unsigned ata_exec_internal_sg(struct ata_device
*dev
,
1843 struct ata_taskfile
*tf
, const u8
*cdb
,
1844 int dma_dir
, struct scatterlist
*sgl
,
1845 unsigned int n_elem
, unsigned long timeout
)
1847 struct ata_link
*link
= dev
->link
;
1848 struct ata_port
*ap
= link
->ap
;
1849 u8 command
= tf
->command
;
1850 struct ata_queued_cmd
*qc
;
1851 unsigned int tag
, preempted_tag
;
1852 u32 preempted_sactive
, preempted_qc_active
;
1853 int preempted_nr_active_links
;
1854 DECLARE_COMPLETION_ONSTACK(wait
);
1855 unsigned long flags
;
1856 unsigned int err_mask
;
1859 spin_lock_irqsave(ap
->lock
, flags
);
1861 /* no internal command while frozen */
1862 if (ap
->pflags
& ATA_PFLAG_FROZEN
) {
1863 spin_unlock_irqrestore(ap
->lock
, flags
);
1864 return AC_ERR_SYSTEM
;
1867 /* initialize internal qc */
1869 /* XXX: Tag 0 is used for drivers with legacy EH as some
1870 * drivers choke if any other tag is given. This breaks
1871 * ata_tag_internal() test for those drivers. Don't use new
1872 * EH stuff without converting to it.
1874 if (ap
->ops
->error_handler
)
1875 tag
= ATA_TAG_INTERNAL
;
1879 if (test_and_set_bit(tag
, &ap
->qc_allocated
))
1881 qc
= __ata_qc_from_tag(ap
, tag
);
1889 preempted_tag
= link
->active_tag
;
1890 preempted_sactive
= link
->sactive
;
1891 preempted_qc_active
= ap
->qc_active
;
1892 preempted_nr_active_links
= ap
->nr_active_links
;
1893 link
->active_tag
= ATA_TAG_POISON
;
1896 ap
->nr_active_links
= 0;
1898 /* prepare & issue qc */
1901 memcpy(qc
->cdb
, cdb
, ATAPI_CDB_LEN
);
1902 qc
->flags
|= ATA_QCFLAG_RESULT_TF
;
1903 qc
->dma_dir
= dma_dir
;
1904 if (dma_dir
!= DMA_NONE
) {
1905 unsigned int i
, buflen
= 0;
1906 struct scatterlist
*sg
;
1908 for_each_sg(sgl
, sg
, n_elem
, i
)
1909 buflen
+= sg
->length
;
1911 ata_sg_init(qc
, sgl
, n_elem
);
1912 qc
->nbytes
= buflen
;
1915 qc
->private_data
= &wait
;
1916 qc
->complete_fn
= ata_qc_complete_internal
;
1920 spin_unlock_irqrestore(ap
->lock
, flags
);
1923 timeout
= ata_probe_timeout
* 1000 / HZ
;
1925 rc
= wait_for_completion_timeout(&wait
, msecs_to_jiffies(timeout
));
1927 ata_port_flush_task(ap
);
1930 spin_lock_irqsave(ap
->lock
, flags
);
1932 /* We're racing with irq here. If we lose, the
1933 * following test prevents us from completing the qc
1934 * twice. If we win, the port is frozen and will be
1935 * cleaned up by ->post_internal_cmd().
1937 if (qc
->flags
& ATA_QCFLAG_ACTIVE
) {
1938 qc
->err_mask
|= AC_ERR_TIMEOUT
;
1940 if (ap
->ops
->error_handler
)
1941 ata_port_freeze(ap
);
1943 ata_qc_complete(qc
);
1945 if (ata_msg_warn(ap
))
1946 ata_dev_printk(dev
, KERN_WARNING
,
1947 "qc timeout (cmd 0x%x)\n", command
);
1950 spin_unlock_irqrestore(ap
->lock
, flags
);
1953 /* do post_internal_cmd */
1954 if (ap
->ops
->post_internal_cmd
)
1955 ap
->ops
->post_internal_cmd(qc
);
1957 /* perform minimal error analysis */
1958 if (qc
->flags
& ATA_QCFLAG_FAILED
) {
1959 if (qc
->result_tf
.command
& (ATA_ERR
| ATA_DF
))
1960 qc
->err_mask
|= AC_ERR_DEV
;
1963 qc
->err_mask
|= AC_ERR_OTHER
;
1965 if (qc
->err_mask
& ~AC_ERR_OTHER
)
1966 qc
->err_mask
&= ~AC_ERR_OTHER
;
1970 spin_lock_irqsave(ap
->lock
, flags
);
1972 *tf
= qc
->result_tf
;
1973 err_mask
= qc
->err_mask
;
1976 link
->active_tag
= preempted_tag
;
1977 link
->sactive
= preempted_sactive
;
1978 ap
->qc_active
= preempted_qc_active
;
1979 ap
->nr_active_links
= preempted_nr_active_links
;
1981 /* XXX - Some LLDDs (sata_mv) disable port on command failure.
1982 * Until those drivers are fixed, we detect the condition
1983 * here, fail the command with AC_ERR_SYSTEM and reenable the
1986 * Note that this doesn't change any behavior as internal
1987 * command failure results in disabling the device in the
1988 * higher layer for LLDDs without new reset/EH callbacks.
1990 * Kill the following code as soon as those drivers are fixed.
1992 if (ap
->flags
& ATA_FLAG_DISABLED
) {
1993 err_mask
|= AC_ERR_SYSTEM
;
1997 spin_unlock_irqrestore(ap
->lock
, flags
);
2003 * ata_exec_internal - execute libata internal command
2004 * @dev: Device to which the command is sent
2005 * @tf: Taskfile registers for the command and the result
2006 * @cdb: CDB for packet command
2007 * @dma_dir: Data tranfer direction of the command
2008 * @buf: Data buffer of the command
2009 * @buflen: Length of data buffer
2010 * @timeout: Timeout in msecs (0 for default)
2012 * Wrapper around ata_exec_internal_sg() which takes simple
2013 * buffer instead of sg list.
2016 * None. Should be called with kernel context, might sleep.
2019 * Zero on success, AC_ERR_* mask on failure
2021 unsigned ata_exec_internal(struct ata_device
*dev
,
2022 struct ata_taskfile
*tf
, const u8
*cdb
,
2023 int dma_dir
, void *buf
, unsigned int buflen
,
2024 unsigned long timeout
)
2026 struct scatterlist
*psg
= NULL
, sg
;
2027 unsigned int n_elem
= 0;
2029 if (dma_dir
!= DMA_NONE
) {
2031 sg_init_one(&sg
, buf
, buflen
);
2036 return ata_exec_internal_sg(dev
, tf
, cdb
, dma_dir
, psg
, n_elem
,
2041 * ata_do_simple_cmd - execute simple internal command
2042 * @dev: Device to which the command is sent
2043 * @cmd: Opcode to execute
2045 * Execute a 'simple' command, that only consists of the opcode
2046 * 'cmd' itself, without filling any other registers
2049 * Kernel thread context (may sleep).
2052 * Zero on success, AC_ERR_* mask on failure
2054 unsigned int ata_do_simple_cmd(struct ata_device
*dev
, u8 cmd
)
2056 struct ata_taskfile tf
;
2058 ata_tf_init(dev
, &tf
);
2061 tf
.flags
|= ATA_TFLAG_DEVICE
;
2062 tf
.protocol
= ATA_PROT_NODATA
;
2064 return ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
2068 * ata_pio_need_iordy - check if iordy needed
2071 * Check if the current speed of the device requires IORDY. Used
2072 * by various controllers for chip configuration.
2075 unsigned int ata_pio_need_iordy(const struct ata_device
*adev
)
2077 /* Controller doesn't support IORDY. Probably a pointless check
2078 as the caller should know this */
2079 if (adev
->link
->ap
->flags
& ATA_FLAG_NO_IORDY
)
2081 /* PIO3 and higher it is mandatory */
2082 if (adev
->pio_mode
> XFER_PIO_2
)
2084 /* We turn it on when possible */
2085 if (ata_id_has_iordy(adev
->id
))
2091 * ata_pio_mask_no_iordy - Return the non IORDY mask
2094 * Compute the highest mode possible if we are not using iordy. Return
2095 * -1 if no iordy mode is available.
2098 static u32
ata_pio_mask_no_iordy(const struct ata_device
*adev
)
2100 /* If we have no drive specific rule, then PIO 2 is non IORDY */
2101 if (adev
->id
[ATA_ID_FIELD_VALID
] & 2) { /* EIDE */
2102 u16 pio
= adev
->id
[ATA_ID_EIDE_PIO
];
2103 /* Is the speed faster than the drive allows non IORDY ? */
2105 /* This is cycle times not frequency - watch the logic! */
2106 if (pio
> 240) /* PIO2 is 240nS per cycle */
2107 return 3 << ATA_SHIFT_PIO
;
2108 return 7 << ATA_SHIFT_PIO
;
2111 return 3 << ATA_SHIFT_PIO
;
2115 * ata_dev_read_id - Read ID data from the specified device
2116 * @dev: target device
2117 * @p_class: pointer to class of the target device (may be changed)
2118 * @flags: ATA_READID_* flags
2119 * @id: buffer to read IDENTIFY data into
2121 * Read ID data from the specified device. ATA_CMD_ID_ATA is
2122 * performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
2123 * devices. This function also issues ATA_CMD_INIT_DEV_PARAMS
2124 * for pre-ATA4 drives.
2126 * FIXME: ATA_CMD_ID_ATA is optional for early drives and right
2127 * now we abort if we hit that case.
2130 * Kernel thread context (may sleep)
2133 * 0 on success, -errno otherwise.
2135 int ata_dev_read_id(struct ata_device
*dev
, unsigned int *p_class
,
2136 unsigned int flags
, u16
*id
)
2138 struct ata_port
*ap
= dev
->link
->ap
;
2139 unsigned int class = *p_class
;
2140 struct ata_taskfile tf
;
2141 unsigned int err_mask
= 0;
2143 int may_fallback
= 1, tried_spinup
= 0;
2146 if (ata_msg_ctl(ap
))
2147 ata_dev_printk(dev
, KERN_DEBUG
, "%s: ENTER\n", __func__
);
2149 ata_dev_select(ap
, dev
->devno
, 1, 1); /* select device 0/1 */
2151 ata_tf_init(dev
, &tf
);
2155 tf
.command
= ATA_CMD_ID_ATA
;
2158 tf
.command
= ATA_CMD_ID_ATAPI
;
2162 reason
= "unsupported class";
2166 tf
.protocol
= ATA_PROT_PIO
;
2168 /* Some devices choke if TF registers contain garbage. Make
2169 * sure those are properly initialized.
2171 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
2173 /* Device presence detection is unreliable on some
2174 * controllers. Always poll IDENTIFY if available.
2176 tf
.flags
|= ATA_TFLAG_POLLING
;
2178 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_FROM_DEVICE
,
2179 id
, sizeof(id
[0]) * ATA_ID_WORDS
, 0);
2181 if (err_mask
& AC_ERR_NODEV_HINT
) {
2182 ata_dev_printk(dev
, KERN_DEBUG
,
2183 "NODEV after polling detection\n");
2187 if ((err_mask
== AC_ERR_DEV
) && (tf
.feature
& ATA_ABORTED
)) {
2188 /* Device or controller might have reported
2189 * the wrong device class. Give a shot at the
2190 * other IDENTIFY if the current one is
2191 * aborted by the device.
2196 if (class == ATA_DEV_ATA
)
2197 class = ATA_DEV_ATAPI
;
2199 class = ATA_DEV_ATA
;
2203 /* Control reaches here iff the device aborted
2204 * both flavors of IDENTIFYs which happens
2205 * sometimes with phantom devices.
2207 ata_dev_printk(dev
, KERN_DEBUG
,
2208 "both IDENTIFYs aborted, assuming NODEV\n");
2213 reason
= "I/O error";
2217 /* Falling back doesn't make sense if ID data was read
2218 * successfully at least once.
2222 swap_buf_le16(id
, ATA_ID_WORDS
);
2226 reason
= "device reports invalid type";
2228 if (class == ATA_DEV_ATA
) {
2229 if (!ata_id_is_ata(id
) && !ata_id_is_cfa(id
))
2232 if (ata_id_is_ata(id
))
2236 if (!tried_spinup
&& (id
[2] == 0x37c8 || id
[2] == 0x738c)) {
2239 * Drive powered-up in standby mode, and requires a specific
2240 * SET_FEATURES spin-up subcommand before it will accept
2241 * anything other than the original IDENTIFY command.
2243 err_mask
= ata_dev_set_feature(dev
, SETFEATURES_SPINUP
, 0);
2244 if (err_mask
&& id
[2] != 0x738c) {
2246 reason
= "SPINUP failed";
2250 * If the drive initially returned incomplete IDENTIFY info,
2251 * we now must reissue the IDENTIFY command.
2253 if (id
[2] == 0x37c8)
2257 if ((flags
& ATA_READID_POSTRESET
) && class == ATA_DEV_ATA
) {
2259 * The exact sequence expected by certain pre-ATA4 drives is:
2261 * IDENTIFY (optional in early ATA)
2262 * INITIALIZE DEVICE PARAMETERS (later IDE and ATA)
2264 * Some drives were very specific about that exact sequence.
2266 * Note that ATA4 says lba is mandatory so the second check
2267 * shoud never trigger.
2269 if (ata_id_major_version(id
) < 4 || !ata_id_has_lba(id
)) {
2270 err_mask
= ata_dev_init_params(dev
, id
[3], id
[6]);
2273 reason
= "INIT_DEV_PARAMS failed";
2277 /* current CHS translation info (id[53-58]) might be
2278 * changed. reread the identify device info.
2280 flags
&= ~ATA_READID_POSTRESET
;
2290 if (ata_msg_warn(ap
))
2291 ata_dev_printk(dev
, KERN_WARNING
, "failed to IDENTIFY "
2292 "(%s, err_mask=0x%x)\n", reason
, err_mask
);
2296 static inline u8
ata_dev_knobble(struct ata_device
*dev
)
2298 struct ata_port
*ap
= dev
->link
->ap
;
2299 return ((ap
->cbl
== ATA_CBL_SATA
) && (!ata_id_is_sata(dev
->id
)));
2302 static void ata_dev_config_ncq(struct ata_device
*dev
,
2303 char *desc
, size_t desc_sz
)
2305 struct ata_port
*ap
= dev
->link
->ap
;
2306 int hdepth
= 0, ddepth
= ata_id_queue_depth(dev
->id
);
2308 if (!ata_id_has_ncq(dev
->id
)) {
2312 if (dev
->horkage
& ATA_HORKAGE_NONCQ
) {
2313 snprintf(desc
, desc_sz
, "NCQ (not used)");
2316 if (ap
->flags
& ATA_FLAG_NCQ
) {
2317 hdepth
= min(ap
->scsi_host
->can_queue
, ATA_MAX_QUEUE
- 1);
2318 dev
->flags
|= ATA_DFLAG_NCQ
;
2321 if (hdepth
>= ddepth
)
2322 snprintf(desc
, desc_sz
, "NCQ (depth %d)", ddepth
);
2324 snprintf(desc
, desc_sz
, "NCQ (depth %d/%d)", hdepth
, ddepth
);
2328 * ata_dev_configure - Configure the specified ATA/ATAPI device
2329 * @dev: Target device to configure
2331 * Configure @dev according to @dev->id. Generic and low-level
2332 * driver specific fixups are also applied.
2335 * Kernel thread context (may sleep)
2338 * 0 on success, -errno otherwise
2340 int ata_dev_configure(struct ata_device
*dev
)
2342 struct ata_port
*ap
= dev
->link
->ap
;
2343 struct ata_eh_context
*ehc
= &dev
->link
->eh_context
;
2344 int print_info
= ehc
->i
.flags
& ATA_EHI_PRINTINFO
;
2345 const u16
*id
= dev
->id
;
2346 unsigned long xfer_mask
;
2347 char revbuf
[7]; /* XYZ-99\0 */
2348 char fwrevbuf
[ATA_ID_FW_REV_LEN
+1];
2349 char modelbuf
[ATA_ID_PROD_LEN
+1];
2352 if (!ata_dev_enabled(dev
) && ata_msg_info(ap
)) {
2353 ata_dev_printk(dev
, KERN_INFO
, "%s: ENTER/EXIT -- nodev\n",
2358 if (ata_msg_probe(ap
))
2359 ata_dev_printk(dev
, KERN_DEBUG
, "%s: ENTER\n", __func__
);
2362 dev
->horkage
|= ata_dev_blacklisted(dev
);
2363 ata_force_horkage(dev
);
2365 /* let ACPI work its magic */
2366 rc
= ata_acpi_on_devcfg(dev
);
2370 /* massage HPA, do it early as it might change IDENTIFY data */
2371 rc
= ata_hpa_resize(dev
);
2375 /* print device capabilities */
2376 if (ata_msg_probe(ap
))
2377 ata_dev_printk(dev
, KERN_DEBUG
,
2378 "%s: cfg 49:%04x 82:%04x 83:%04x 84:%04x "
2379 "85:%04x 86:%04x 87:%04x 88:%04x\n",
2381 id
[49], id
[82], id
[83], id
[84],
2382 id
[85], id
[86], id
[87], id
[88]);
2384 /* initialize to-be-configured parameters */
2385 dev
->flags
&= ~ATA_DFLAG_CFG_MASK
;
2386 dev
->max_sectors
= 0;
2394 * common ATA, ATAPI feature tests
2397 /* find max transfer mode; for printk only */
2398 xfer_mask
= ata_id_xfermask(id
);
2400 if (ata_msg_probe(ap
))
2403 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
2404 ata_id_c_string(dev
->id
, fwrevbuf
, ATA_ID_FW_REV
,
2407 ata_id_c_string(dev
->id
, modelbuf
, ATA_ID_PROD
,
2410 /* ATA-specific feature tests */
2411 if (dev
->class == ATA_DEV_ATA
) {
2412 if (ata_id_is_cfa(id
)) {
2413 if (id
[162] & 1) /* CPRM may make this media unusable */
2414 ata_dev_printk(dev
, KERN_WARNING
,
2415 "supports DRM functions and may "
2416 "not be fully accessable.\n");
2417 snprintf(revbuf
, 7, "CFA");
2419 snprintf(revbuf
, 7, "ATA-%d", ata_id_major_version(id
));
2420 /* Warn the user if the device has TPM extensions */
2421 if (ata_id_has_tpm(id
))
2422 ata_dev_printk(dev
, KERN_WARNING
,
2423 "supports DRM functions and may "
2424 "not be fully accessable.\n");
2427 dev
->n_sectors
= ata_id_n_sectors(id
);
2429 if (dev
->id
[59] & 0x100)
2430 dev
->multi_count
= dev
->id
[59] & 0xff;
2432 if (ata_id_has_lba(id
)) {
2433 const char *lba_desc
;
2437 dev
->flags
|= ATA_DFLAG_LBA
;
2438 if (ata_id_has_lba48(id
)) {
2439 dev
->flags
|= ATA_DFLAG_LBA48
;
2442 if (dev
->n_sectors
>= (1UL << 28) &&
2443 ata_id_has_flush_ext(id
))
2444 dev
->flags
|= ATA_DFLAG_FLUSH_EXT
;
2448 ata_dev_config_ncq(dev
, ncq_desc
, sizeof(ncq_desc
));
2450 /* print device info to dmesg */
2451 if (ata_msg_drv(ap
) && print_info
) {
2452 ata_dev_printk(dev
, KERN_INFO
,
2453 "%s: %s, %s, max %s\n",
2454 revbuf
, modelbuf
, fwrevbuf
,
2455 ata_mode_string(xfer_mask
));
2456 ata_dev_printk(dev
, KERN_INFO
,
2457 "%Lu sectors, multi %u: %s %s\n",
2458 (unsigned long long)dev
->n_sectors
,
2459 dev
->multi_count
, lba_desc
, ncq_desc
);
2464 /* Default translation */
2465 dev
->cylinders
= id
[1];
2467 dev
->sectors
= id
[6];
2469 if (ata_id_current_chs_valid(id
)) {
2470 /* Current CHS translation is valid. */
2471 dev
->cylinders
= id
[54];
2472 dev
->heads
= id
[55];
2473 dev
->sectors
= id
[56];
2476 /* print device info to dmesg */
2477 if (ata_msg_drv(ap
) && print_info
) {
2478 ata_dev_printk(dev
, KERN_INFO
,
2479 "%s: %s, %s, max %s\n",
2480 revbuf
, modelbuf
, fwrevbuf
,
2481 ata_mode_string(xfer_mask
));
2482 ata_dev_printk(dev
, KERN_INFO
,
2483 "%Lu sectors, multi %u, CHS %u/%u/%u\n",
2484 (unsigned long long)dev
->n_sectors
,
2485 dev
->multi_count
, dev
->cylinders
,
2486 dev
->heads
, dev
->sectors
);
2493 /* ATAPI-specific feature tests */
2494 else if (dev
->class == ATA_DEV_ATAPI
) {
2495 const char *cdb_intr_string
= "";
2496 const char *atapi_an_string
= "";
2497 const char *dma_dir_string
= "";
2500 rc
= atapi_cdb_len(id
);
2501 if ((rc
< 12) || (rc
> ATAPI_CDB_LEN
)) {
2502 if (ata_msg_warn(ap
))
2503 ata_dev_printk(dev
, KERN_WARNING
,
2504 "unsupported CDB len\n");
2508 dev
->cdb_len
= (unsigned int) rc
;
2510 /* Enable ATAPI AN if both the host and device have
2511 * the support. If PMP is attached, SNTF is required
2512 * to enable ATAPI AN to discern between PHY status
2513 * changed notifications and ATAPI ANs.
2515 if ((ap
->flags
& ATA_FLAG_AN
) && ata_id_has_atapi_AN(id
) &&
2516 (!ap
->nr_pmp_links
||
2517 sata_scr_read(&ap
->link
, SCR_NOTIFICATION
, &sntf
) == 0)) {
2518 unsigned int err_mask
;
2520 /* issue SET feature command to turn this on */
2521 err_mask
= ata_dev_set_feature(dev
,
2522 SETFEATURES_SATA_ENABLE
, SATA_AN
);
2524 ata_dev_printk(dev
, KERN_ERR
,
2525 "failed to enable ATAPI AN "
2526 "(err_mask=0x%x)\n", err_mask
);
2528 dev
->flags
|= ATA_DFLAG_AN
;
2529 atapi_an_string
= ", ATAPI AN";
2533 if (ata_id_cdb_intr(dev
->id
)) {
2534 dev
->flags
|= ATA_DFLAG_CDB_INTR
;
2535 cdb_intr_string
= ", CDB intr";
2538 if (atapi_dmadir
|| atapi_id_dmadir(dev
->id
)) {
2539 dev
->flags
|= ATA_DFLAG_DMADIR
;
2540 dma_dir_string
= ", DMADIR";
2543 /* print device info to dmesg */
2544 if (ata_msg_drv(ap
) && print_info
)
2545 ata_dev_printk(dev
, KERN_INFO
,
2546 "ATAPI: %s, %s, max %s%s%s%s\n",
2548 ata_mode_string(xfer_mask
),
2549 cdb_intr_string
, atapi_an_string
,
2553 /* determine max_sectors */
2554 dev
->max_sectors
= ATA_MAX_SECTORS
;
2555 if (dev
->flags
& ATA_DFLAG_LBA48
)
2556 dev
->max_sectors
= ATA_MAX_SECTORS_LBA48
;
2558 if (!(dev
->horkage
& ATA_HORKAGE_IPM
)) {
2559 if (ata_id_has_hipm(dev
->id
))
2560 dev
->flags
|= ATA_DFLAG_HIPM
;
2561 if (ata_id_has_dipm(dev
->id
))
2562 dev
->flags
|= ATA_DFLAG_DIPM
;
2565 /* Limit PATA drive on SATA cable bridge transfers to udma5,
2567 if (ata_dev_knobble(dev
)) {
2568 if (ata_msg_drv(ap
) && print_info
)
2569 ata_dev_printk(dev
, KERN_INFO
,
2570 "applying bridge limits\n");
2571 dev
->udma_mask
&= ATA_UDMA5
;
2572 dev
->max_sectors
= ATA_MAX_SECTORS
;
2575 if ((dev
->class == ATA_DEV_ATAPI
) &&
2576 (atapi_command_packet_set(id
) == TYPE_TAPE
)) {
2577 dev
->max_sectors
= ATA_MAX_SECTORS_TAPE
;
2578 dev
->horkage
|= ATA_HORKAGE_STUCK_ERR
;
2581 if (dev
->horkage
& ATA_HORKAGE_MAX_SEC_128
)
2582 dev
->max_sectors
= min_t(unsigned int, ATA_MAX_SECTORS_128
,
2585 if (ata_dev_blacklisted(dev
) & ATA_HORKAGE_IPM
) {
2586 dev
->horkage
|= ATA_HORKAGE_IPM
;
2588 /* reset link pm_policy for this port to no pm */
2589 ap
->pm_policy
= MAX_PERFORMANCE
;
2592 if (ap
->ops
->dev_config
)
2593 ap
->ops
->dev_config(dev
);
2595 if (dev
->horkage
& ATA_HORKAGE_DIAGNOSTIC
) {
2596 /* Let the user know. We don't want to disallow opens for
2597 rescue purposes, or in case the vendor is just a blithering
2598 idiot. Do this after the dev_config call as some controllers
2599 with buggy firmware may want to avoid reporting false device
2603 ata_dev_printk(dev
, KERN_WARNING
,
2604 "Drive reports diagnostics failure. This may indicate a drive\n");
2605 ata_dev_printk(dev
, KERN_WARNING
,
2606 "fault or invalid emulation. Contact drive vendor for information.\n");
2610 if (ata_msg_probe(ap
))
2611 ata_dev_printk(dev
, KERN_DEBUG
, "%s: EXIT, drv_stat = 0x%x\n",
2612 __func__
, ata_chk_status(ap
));
2616 if (ata_msg_probe(ap
))
2617 ata_dev_printk(dev
, KERN_DEBUG
,
2618 "%s: EXIT, err\n", __func__
);
2623 * ata_cable_40wire - return 40 wire cable type
2626 * Helper method for drivers which want to hardwire 40 wire cable
2630 int ata_cable_40wire(struct ata_port
*ap
)
2632 return ATA_CBL_PATA40
;
2636 * ata_cable_80wire - return 80 wire cable type
2639 * Helper method for drivers which want to hardwire 80 wire cable
2643 int ata_cable_80wire(struct ata_port
*ap
)
2645 return ATA_CBL_PATA80
;
2649 * ata_cable_unknown - return unknown PATA cable.
2652 * Helper method for drivers which have no PATA cable detection.
2655 int ata_cable_unknown(struct ata_port
*ap
)
2657 return ATA_CBL_PATA_UNK
;
2661 * ata_cable_ignore - return ignored PATA cable.
2664 * Helper method for drivers which don't use cable type to limit
2667 int ata_cable_ignore(struct ata_port
*ap
)
2669 return ATA_CBL_PATA_IGN
;
2673 * ata_cable_sata - return SATA cable type
2676 * Helper method for drivers which have SATA cables
2679 int ata_cable_sata(struct ata_port
*ap
)
2681 return ATA_CBL_SATA
;
2685 * ata_bus_probe - Reset and probe ATA bus
2688 * Master ATA bus probing function. Initiates a hardware-dependent
2689 * bus reset, then attempts to identify any devices found on
2693 * PCI/etc. bus probe sem.
2696 * Zero on success, negative errno otherwise.
2699 int ata_bus_probe(struct ata_port
*ap
)
2701 unsigned int classes
[ATA_MAX_DEVICES
];
2702 int tries
[ATA_MAX_DEVICES
];
2704 struct ata_device
*dev
;
2708 ata_link_for_each_dev(dev
, &ap
->link
)
2709 tries
[dev
->devno
] = ATA_PROBE_MAX_TRIES
;
2712 ata_link_for_each_dev(dev
, &ap
->link
) {
2713 /* If we issue an SRST then an ATA drive (not ATAPI)
2714 * may change configuration and be in PIO0 timing. If
2715 * we do a hard reset (or are coming from power on)
2716 * this is true for ATA or ATAPI. Until we've set a
2717 * suitable controller mode we should not touch the
2718 * bus as we may be talking too fast.
2720 dev
->pio_mode
= XFER_PIO_0
;
2722 /* If the controller has a pio mode setup function
2723 * then use it to set the chipset to rights. Don't
2724 * touch the DMA setup as that will be dealt with when
2725 * configuring devices.
2727 if (ap
->ops
->set_piomode
)
2728 ap
->ops
->set_piomode(ap
, dev
);
2731 /* reset and determine device classes */
2732 ap
->ops
->phy_reset(ap
);
2734 ata_link_for_each_dev(dev
, &ap
->link
) {
2735 if (!(ap
->flags
& ATA_FLAG_DISABLED
) &&
2736 dev
->class != ATA_DEV_UNKNOWN
)
2737 classes
[dev
->devno
] = dev
->class;
2739 classes
[dev
->devno
] = ATA_DEV_NONE
;
2741 dev
->class = ATA_DEV_UNKNOWN
;
2746 /* read IDENTIFY page and configure devices. We have to do the identify
2747 specific sequence bass-ackwards so that PDIAG- is released by
2750 ata_link_for_each_dev_reverse(dev
, &ap
->link
) {
2751 if (tries
[dev
->devno
])
2752 dev
->class = classes
[dev
->devno
];
2754 if (!ata_dev_enabled(dev
))
2757 rc
= ata_dev_read_id(dev
, &dev
->class, ATA_READID_POSTRESET
,
2763 /* Now ask for the cable type as PDIAG- should have been released */
2764 if (ap
->ops
->cable_detect
)
2765 ap
->cbl
= ap
->ops
->cable_detect(ap
);
2767 /* We may have SATA bridge glue hiding here irrespective of the
2768 reported cable types and sensed types */
2769 ata_link_for_each_dev(dev
, &ap
->link
) {
2770 if (!ata_dev_enabled(dev
))
2772 /* SATA drives indicate we have a bridge. We don't know which
2773 end of the link the bridge is which is a problem */
2774 if (ata_id_is_sata(dev
->id
))
2775 ap
->cbl
= ATA_CBL_SATA
;
2778 /* After the identify sequence we can now set up the devices. We do
2779 this in the normal order so that the user doesn't get confused */
2781 ata_link_for_each_dev(dev
, &ap
->link
) {
2782 if (!ata_dev_enabled(dev
))
2785 ap
->link
.eh_context
.i
.flags
|= ATA_EHI_PRINTINFO
;
2786 rc
= ata_dev_configure(dev
);
2787 ap
->link
.eh_context
.i
.flags
&= ~ATA_EHI_PRINTINFO
;
2792 /* configure transfer mode */
2793 rc
= ata_set_mode(&ap
->link
, &dev
);
2797 ata_link_for_each_dev(dev
, &ap
->link
)
2798 if (ata_dev_enabled(dev
))
2801 /* no device present, disable port */
2802 ata_port_disable(ap
);
2806 tries
[dev
->devno
]--;
2810 /* eeek, something went very wrong, give up */
2811 tries
[dev
->devno
] = 0;
2815 /* give it just one more chance */
2816 tries
[dev
->devno
] = min(tries
[dev
->devno
], 1);
2818 if (tries
[dev
->devno
] == 1) {
2819 /* This is the last chance, better to slow
2820 * down than lose it.
2822 sata_down_spd_limit(&ap
->link
);
2823 ata_down_xfermask_limit(dev
, ATA_DNXFER_PIO
);
2827 if (!tries
[dev
->devno
])
2828 ata_dev_disable(dev
);
2834 * ata_port_probe - Mark port as enabled
2835 * @ap: Port for which we indicate enablement
2837 * Modify @ap data structure such that the system
2838 * thinks that the entire port is enabled.
2840 * LOCKING: host lock, or some other form of
2844 void ata_port_probe(struct ata_port
*ap
)
2846 ap
->flags
&= ~ATA_FLAG_DISABLED
;
2850 * sata_print_link_status - Print SATA link status
2851 * @link: SATA link to printk link status about
2853 * This function prints link speed and status of a SATA link.
2858 void sata_print_link_status(struct ata_link
*link
)
2860 u32 sstatus
, scontrol
, tmp
;
2862 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
))
2864 sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
2866 if (ata_link_online(link
)) {
2867 tmp
= (sstatus
>> 4) & 0xf;
2868 ata_link_printk(link
, KERN_INFO
,
2869 "SATA link up %s (SStatus %X SControl %X)\n",
2870 sata_spd_string(tmp
), sstatus
, scontrol
);
2872 ata_link_printk(link
, KERN_INFO
,
2873 "SATA link down (SStatus %X SControl %X)\n",
2879 * ata_dev_pair - return other device on cable
2882 * Obtain the other device on the same cable, or if none is
2883 * present NULL is returned
2886 struct ata_device
*ata_dev_pair(struct ata_device
*adev
)
2888 struct ata_link
*link
= adev
->link
;
2889 struct ata_device
*pair
= &link
->device
[1 - adev
->devno
];
2890 if (!ata_dev_enabled(pair
))
2896 * ata_port_disable - Disable port.
2897 * @ap: Port to be disabled.
2899 * Modify @ap data structure such that the system
2900 * thinks that the entire port is disabled, and should
2901 * never attempt to probe or communicate with devices
2904 * LOCKING: host lock, or some other form of
2908 void ata_port_disable(struct ata_port
*ap
)
2910 ap
->link
.device
[0].class = ATA_DEV_NONE
;
2911 ap
->link
.device
[1].class = ATA_DEV_NONE
;
2912 ap
->flags
|= ATA_FLAG_DISABLED
;
2916 * sata_down_spd_limit - adjust SATA spd limit downward
2917 * @link: Link to adjust SATA spd limit for
2919 * Adjust SATA spd limit of @link downward. Note that this
2920 * function only adjusts the limit. The change must be applied
2921 * using sata_set_spd().
2924 * Inherited from caller.
2927 * 0 on success, negative errno on failure
2929 int sata_down_spd_limit(struct ata_link
*link
)
2931 u32 sstatus
, spd
, mask
;
2934 if (!sata_scr_valid(link
))
2937 /* If SCR can be read, use it to determine the current SPD.
2938 * If not, use cached value in link->sata_spd.
2940 rc
= sata_scr_read(link
, SCR_STATUS
, &sstatus
);
2942 spd
= (sstatus
>> 4) & 0xf;
2944 spd
= link
->sata_spd
;
2946 mask
= link
->sata_spd_limit
;
2950 /* unconditionally mask off the highest bit */
2951 highbit
= fls(mask
) - 1;
2952 mask
&= ~(1 << highbit
);
2954 /* Mask off all speeds higher than or equal to the current
2955 * one. Force 1.5Gbps if current SPD is not available.
2958 mask
&= (1 << (spd
- 1)) - 1;
2962 /* were we already at the bottom? */
2966 link
->sata_spd_limit
= mask
;
2968 ata_link_printk(link
, KERN_WARNING
, "limiting SATA link speed to %s\n",
2969 sata_spd_string(fls(mask
)));
2974 static int __sata_set_spd_needed(struct ata_link
*link
, u32
*scontrol
)
2976 struct ata_link
*host_link
= &link
->ap
->link
;
2977 u32 limit
, target
, spd
;
2979 limit
= link
->sata_spd_limit
;
2981 /* Don't configure downstream link faster than upstream link.
2982 * It doesn't speed up anything and some PMPs choke on such
2985 if (!ata_is_host_link(link
) && host_link
->sata_spd
)
2986 limit
&= (1 << host_link
->sata_spd
) - 1;
2988 if (limit
== UINT_MAX
)
2991 target
= fls(limit
);
2993 spd
= (*scontrol
>> 4) & 0xf;
2994 *scontrol
= (*scontrol
& ~0xf0) | ((target
& 0xf) << 4);
2996 return spd
!= target
;
3000 * sata_set_spd_needed - is SATA spd configuration needed
3001 * @link: Link in question
3003 * Test whether the spd limit in SControl matches
3004 * @link->sata_spd_limit. This function is used to determine
3005 * whether hardreset is necessary to apply SATA spd
3009 * Inherited from caller.
3012 * 1 if SATA spd configuration is needed, 0 otherwise.
3014 int sata_set_spd_needed(struct ata_link
*link
)
3018 if (sata_scr_read(link
, SCR_CONTROL
, &scontrol
))
3021 return __sata_set_spd_needed(link
, &scontrol
);
3025 * sata_set_spd - set SATA spd according to spd limit
3026 * @link: Link to set SATA spd for
3028 * Set SATA spd of @link according to sata_spd_limit.
3031 * Inherited from caller.
3034 * 0 if spd doesn't need to be changed, 1 if spd has been
3035 * changed. Negative errno if SCR registers are inaccessible.
3037 int sata_set_spd(struct ata_link
*link
)
3042 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
3045 if (!__sata_set_spd_needed(link
, &scontrol
))
3048 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
3055 * This mode timing computation functionality is ported over from
3056 * drivers/ide/ide-timing.h and was originally written by Vojtech Pavlik
3059 * PIO 0-4, MWDMA 0-2 and UDMA 0-6 timings (in nanoseconds).
3060 * These were taken from ATA/ATAPI-6 standard, rev 0a, except
3061 * for UDMA6, which is currently supported only by Maxtor drives.
3063 * For PIO 5/6 MWDMA 3/4 see the CFA specification 3.0.
3066 static const struct ata_timing ata_timing
[] = {
3067 /* { XFER_PIO_SLOW, 120, 290, 240, 960, 290, 240, 960, 0 }, */
3068 { XFER_PIO_0
, 70, 290, 240, 600, 165, 150, 600, 0 },
3069 { XFER_PIO_1
, 50, 290, 93, 383, 125, 100, 383, 0 },
3070 { XFER_PIO_2
, 30, 290, 40, 330, 100, 90, 240, 0 },
3071 { XFER_PIO_3
, 30, 80, 70, 180, 80, 70, 180, 0 },
3072 { XFER_PIO_4
, 25, 70, 25, 120, 70, 25, 120, 0 },
3073 { XFER_PIO_5
, 15, 65, 25, 100, 65, 25, 100, 0 },
3074 { XFER_PIO_6
, 10, 55, 20, 80, 55, 20, 80, 0 },
3076 { XFER_SW_DMA_0
, 120, 0, 0, 0, 480, 480, 960, 0 },
3077 { XFER_SW_DMA_1
, 90, 0, 0, 0, 240, 240, 480, 0 },
3078 { XFER_SW_DMA_2
, 60, 0, 0, 0, 120, 120, 240, 0 },
3080 { XFER_MW_DMA_0
, 60, 0, 0, 0, 215, 215, 480, 0 },
3081 { XFER_MW_DMA_1
, 45, 0, 0, 0, 80, 50, 150, 0 },
3082 { XFER_MW_DMA_2
, 25, 0, 0, 0, 70, 25, 120, 0 },
3083 { XFER_MW_DMA_3
, 25, 0, 0, 0, 65, 25, 100, 0 },
3084 { XFER_MW_DMA_4
, 25, 0, 0, 0, 55, 20, 80, 0 },
3086 /* { XFER_UDMA_SLOW, 0, 0, 0, 0, 0, 0, 0, 150 }, */
3087 { XFER_UDMA_0
, 0, 0, 0, 0, 0, 0, 0, 120 },
3088 { XFER_UDMA_1
, 0, 0, 0, 0, 0, 0, 0, 80 },
3089 { XFER_UDMA_2
, 0, 0, 0, 0, 0, 0, 0, 60 },
3090 { XFER_UDMA_3
, 0, 0, 0, 0, 0, 0, 0, 45 },
3091 { XFER_UDMA_4
, 0, 0, 0, 0, 0, 0, 0, 30 },
3092 { XFER_UDMA_5
, 0, 0, 0, 0, 0, 0, 0, 20 },
3093 { XFER_UDMA_6
, 0, 0, 0, 0, 0, 0, 0, 15 },
3098 #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
3099 #define EZ(v, unit) ((v)?ENOUGH(v, unit):0)
3101 static void ata_timing_quantize(const struct ata_timing
*t
, struct ata_timing
*q
, int T
, int UT
)
3103 q
->setup
= EZ(t
->setup
* 1000, T
);
3104 q
->act8b
= EZ(t
->act8b
* 1000, T
);
3105 q
->rec8b
= EZ(t
->rec8b
* 1000, T
);
3106 q
->cyc8b
= EZ(t
->cyc8b
* 1000, T
);
3107 q
->active
= EZ(t
->active
* 1000, T
);
3108 q
->recover
= EZ(t
->recover
* 1000, T
);
3109 q
->cycle
= EZ(t
->cycle
* 1000, T
);
3110 q
->udma
= EZ(t
->udma
* 1000, UT
);
3113 void ata_timing_merge(const struct ata_timing
*a
, const struct ata_timing
*b
,
3114 struct ata_timing
*m
, unsigned int what
)
3116 if (what
& ATA_TIMING_SETUP
) m
->setup
= max(a
->setup
, b
->setup
);
3117 if (what
& ATA_TIMING_ACT8B
) m
->act8b
= max(a
->act8b
, b
->act8b
);
3118 if (what
& ATA_TIMING_REC8B
) m
->rec8b
= max(a
->rec8b
, b
->rec8b
);
3119 if (what
& ATA_TIMING_CYC8B
) m
->cyc8b
= max(a
->cyc8b
, b
->cyc8b
);
3120 if (what
& ATA_TIMING_ACTIVE
) m
->active
= max(a
->active
, b
->active
);
3121 if (what
& ATA_TIMING_RECOVER
) m
->recover
= max(a
->recover
, b
->recover
);
3122 if (what
& ATA_TIMING_CYCLE
) m
->cycle
= max(a
->cycle
, b
->cycle
);
3123 if (what
& ATA_TIMING_UDMA
) m
->udma
= max(a
->udma
, b
->udma
);
3126 const struct ata_timing
*ata_timing_find_mode(u8 xfer_mode
)
3128 const struct ata_timing
*t
= ata_timing
;
3130 while (xfer_mode
> t
->mode
)
3133 if (xfer_mode
== t
->mode
)
3138 int ata_timing_compute(struct ata_device
*adev
, unsigned short speed
,
3139 struct ata_timing
*t
, int T
, int UT
)
3141 const struct ata_timing
*s
;
3142 struct ata_timing p
;
3148 if (!(s
= ata_timing_find_mode(speed
)))
3151 memcpy(t
, s
, sizeof(*s
));
3154 * If the drive is an EIDE drive, it can tell us it needs extended
3155 * PIO/MW_DMA cycle timing.
3158 if (adev
->id
[ATA_ID_FIELD_VALID
] & 2) { /* EIDE drive */
3159 memset(&p
, 0, sizeof(p
));
3160 if (speed
>= XFER_PIO_0
&& speed
<= XFER_SW_DMA_0
) {
3161 if (speed
<= XFER_PIO_2
) p
.cycle
= p
.cyc8b
= adev
->id
[ATA_ID_EIDE_PIO
];
3162 else p
.cycle
= p
.cyc8b
= adev
->id
[ATA_ID_EIDE_PIO_IORDY
];
3163 } else if (speed
>= XFER_MW_DMA_0
&& speed
<= XFER_MW_DMA_2
) {
3164 p
.cycle
= adev
->id
[ATA_ID_EIDE_DMA_MIN
];
3166 ata_timing_merge(&p
, t
, t
, ATA_TIMING_CYCLE
| ATA_TIMING_CYC8B
);
3170 * Convert the timing to bus clock counts.
3173 ata_timing_quantize(t
, t
, T
, UT
);
3176 * Even in DMA/UDMA modes we still use PIO access for IDENTIFY,
3177 * S.M.A.R.T * and some other commands. We have to ensure that the
3178 * DMA cycle timing is slower/equal than the fastest PIO timing.
3181 if (speed
> XFER_PIO_6
) {
3182 ata_timing_compute(adev
, adev
->pio_mode
, &p
, T
, UT
);
3183 ata_timing_merge(&p
, t
, t
, ATA_TIMING_ALL
);
3187 * Lengthen active & recovery time so that cycle time is correct.
3190 if (t
->act8b
+ t
->rec8b
< t
->cyc8b
) {
3191 t
->act8b
+= (t
->cyc8b
- (t
->act8b
+ t
->rec8b
)) / 2;
3192 t
->rec8b
= t
->cyc8b
- t
->act8b
;
3195 if (t
->active
+ t
->recover
< t
->cycle
) {
3196 t
->active
+= (t
->cycle
- (t
->active
+ t
->recover
)) / 2;
3197 t
->recover
= t
->cycle
- t
->active
;
3200 /* In a few cases quantisation may produce enough errors to
3201 leave t->cycle too low for the sum of active and recovery
3202 if so we must correct this */
3203 if (t
->active
+ t
->recover
> t
->cycle
)
3204 t
->cycle
= t
->active
+ t
->recover
;
3210 * ata_timing_cycle2mode - find xfer mode for the specified cycle duration
3211 * @xfer_shift: ATA_SHIFT_* value for transfer type to examine.
3212 * @cycle: cycle duration in ns
3214 * Return matching xfer mode for @cycle. The returned mode is of
3215 * the transfer type specified by @xfer_shift. If @cycle is too
3216 * slow for @xfer_shift, 0xff is returned. If @cycle is faster
3217 * than the fastest known mode, the fasted mode is returned.
3223 * Matching xfer_mode, 0xff if no match found.
3225 u8
ata_timing_cycle2mode(unsigned int xfer_shift
, int cycle
)
3227 u8 base_mode
= 0xff, last_mode
= 0xff;
3228 const struct ata_xfer_ent
*ent
;
3229 const struct ata_timing
*t
;
3231 for (ent
= ata_xfer_tbl
; ent
->shift
>= 0; ent
++)
3232 if (ent
->shift
== xfer_shift
)
3233 base_mode
= ent
->base
;
3235 for (t
= ata_timing_find_mode(base_mode
);
3236 t
&& ata_xfer_mode2shift(t
->mode
) == xfer_shift
; t
++) {
3237 unsigned short this_cycle
;
3239 switch (xfer_shift
) {
3241 case ATA_SHIFT_MWDMA
:
3242 this_cycle
= t
->cycle
;
3244 case ATA_SHIFT_UDMA
:
3245 this_cycle
= t
->udma
;
3251 if (cycle
> this_cycle
)
3254 last_mode
= t
->mode
;
3261 * ata_down_xfermask_limit - adjust dev xfer masks downward
3262 * @dev: Device to adjust xfer masks
3263 * @sel: ATA_DNXFER_* selector
3265 * Adjust xfer masks of @dev downward. Note that this function
3266 * does not apply the change. Invoking ata_set_mode() afterwards
3267 * will apply the limit.
3270 * Inherited from caller.
3273 * 0 on success, negative errno on failure
3275 int ata_down_xfermask_limit(struct ata_device
*dev
, unsigned int sel
)
3278 unsigned long orig_mask
, xfer_mask
;
3279 unsigned long pio_mask
, mwdma_mask
, udma_mask
;
3282 quiet
= !!(sel
& ATA_DNXFER_QUIET
);
3283 sel
&= ~ATA_DNXFER_QUIET
;
3285 xfer_mask
= orig_mask
= ata_pack_xfermask(dev
->pio_mask
,
3288 ata_unpack_xfermask(xfer_mask
, &pio_mask
, &mwdma_mask
, &udma_mask
);
3291 case ATA_DNXFER_PIO
:
3292 highbit
= fls(pio_mask
) - 1;
3293 pio_mask
&= ~(1 << highbit
);
3296 case ATA_DNXFER_DMA
:
3298 highbit
= fls(udma_mask
) - 1;
3299 udma_mask
&= ~(1 << highbit
);
3302 } else if (mwdma_mask
) {
3303 highbit
= fls(mwdma_mask
) - 1;
3304 mwdma_mask
&= ~(1 << highbit
);
3310 case ATA_DNXFER_40C
:
3311 udma_mask
&= ATA_UDMA_MASK_40C
;
3314 case ATA_DNXFER_FORCE_PIO0
:
3316 case ATA_DNXFER_FORCE_PIO
:
3325 xfer_mask
&= ata_pack_xfermask(pio_mask
, mwdma_mask
, udma_mask
);
3327 if (!(xfer_mask
& ATA_MASK_PIO
) || xfer_mask
== orig_mask
)
3331 if (xfer_mask
& (ATA_MASK_MWDMA
| ATA_MASK_UDMA
))
3332 snprintf(buf
, sizeof(buf
), "%s:%s",
3333 ata_mode_string(xfer_mask
),
3334 ata_mode_string(xfer_mask
& ATA_MASK_PIO
));
3336 snprintf(buf
, sizeof(buf
), "%s",
3337 ata_mode_string(xfer_mask
));
3339 ata_dev_printk(dev
, KERN_WARNING
,
3340 "limiting speed to %s\n", buf
);
3343 ata_unpack_xfermask(xfer_mask
, &dev
->pio_mask
, &dev
->mwdma_mask
,
3349 static int ata_dev_set_mode(struct ata_device
*dev
)
3351 struct ata_eh_context
*ehc
= &dev
->link
->eh_context
;
3352 const char *dev_err_whine
= "";
3353 int ign_dev_err
= 0;
3354 unsigned int err_mask
;
3357 dev
->flags
&= ~ATA_DFLAG_PIO
;
3358 if (dev
->xfer_shift
== ATA_SHIFT_PIO
)
3359 dev
->flags
|= ATA_DFLAG_PIO
;
3361 err_mask
= ata_dev_set_xfermode(dev
);
3363 if (err_mask
& ~AC_ERR_DEV
)
3367 ehc
->i
.flags
|= ATA_EHI_POST_SETMODE
;
3368 rc
= ata_dev_revalidate(dev
, ATA_DEV_UNKNOWN
, 0);
3369 ehc
->i
.flags
&= ~ATA_EHI_POST_SETMODE
;
3373 /* Old CFA may refuse this command, which is just fine */
3374 if (dev
->xfer_shift
== ATA_SHIFT_PIO
&& ata_id_is_cfa(dev
->id
))
3377 /* Some very old devices and some bad newer ones fail any kind of
3378 SET_XFERMODE request but support PIO0-2 timings and no IORDY */
3379 if (dev
->xfer_shift
== ATA_SHIFT_PIO
&& !ata_id_has_iordy(dev
->id
) &&
3380 dev
->pio_mode
<= XFER_PIO_2
)
3383 /* Early MWDMA devices do DMA but don't allow DMA mode setting.
3384 Don't fail an MWDMA0 set IFF the device indicates it is in MWDMA0 */
3385 if (dev
->xfer_shift
== ATA_SHIFT_MWDMA
&&
3386 dev
->dma_mode
== XFER_MW_DMA_0
&&
3387 (dev
->id
[63] >> 8) & 1)
3390 /* if the device is actually configured correctly, ignore dev err */
3391 if (dev
->xfer_mode
== ata_xfer_mask2mode(ata_id_xfermask(dev
->id
)))
3394 if (err_mask
& AC_ERR_DEV
) {
3398 dev_err_whine
= " (device error ignored)";
3401 DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
3402 dev
->xfer_shift
, (int)dev
->xfer_mode
);
3404 ata_dev_printk(dev
, KERN_INFO
, "configured for %s%s\n",
3405 ata_mode_string(ata_xfer_mode2mask(dev
->xfer_mode
)),
3411 ata_dev_printk(dev
, KERN_ERR
, "failed to set xfermode "
3412 "(err_mask=0x%x)\n", err_mask
);
3417 * ata_do_set_mode - Program timings and issue SET FEATURES - XFER
3418 * @link: link on which timings will be programmed
3419 * @r_failed_dev: out parameter for failed device
3421 * Standard implementation of the function used to tune and set
3422 * ATA device disk transfer mode (PIO3, UDMA6, etc.). If
3423 * ata_dev_set_mode() fails, pointer to the failing device is
3424 * returned in @r_failed_dev.
3427 * PCI/etc. bus probe sem.
3430 * 0 on success, negative errno otherwise
3433 int ata_do_set_mode(struct ata_link
*link
, struct ata_device
**r_failed_dev
)
3435 struct ata_port
*ap
= link
->ap
;
3436 struct ata_device
*dev
;
3437 int rc
= 0, used_dma
= 0, found
= 0;
3439 /* step 1: calculate xfer_mask */
3440 ata_link_for_each_dev(dev
, link
) {
3441 unsigned long pio_mask
, dma_mask
;
3442 unsigned int mode_mask
;
3444 if (!ata_dev_enabled(dev
))
3447 mode_mask
= ATA_DMA_MASK_ATA
;
3448 if (dev
->class == ATA_DEV_ATAPI
)
3449 mode_mask
= ATA_DMA_MASK_ATAPI
;
3450 else if (ata_id_is_cfa(dev
->id
))
3451 mode_mask
= ATA_DMA_MASK_CFA
;
3453 ata_dev_xfermask(dev
);
3454 ata_force_xfermask(dev
);
3456 pio_mask
= ata_pack_xfermask(dev
->pio_mask
, 0, 0);
3457 dma_mask
= ata_pack_xfermask(0, dev
->mwdma_mask
, dev
->udma_mask
);
3459 if (libata_dma_mask
& mode_mask
)
3460 dma_mask
= ata_pack_xfermask(0, dev
->mwdma_mask
, dev
->udma_mask
);
3464 dev
->pio_mode
= ata_xfer_mask2mode(pio_mask
);
3465 dev
->dma_mode
= ata_xfer_mask2mode(dma_mask
);
3468 if (dev
->dma_mode
!= 0xff)
3474 /* step 2: always set host PIO timings */
3475 ata_link_for_each_dev(dev
, link
) {
3476 if (!ata_dev_enabled(dev
))
3479 if (dev
->pio_mode
== 0xff) {
3480 ata_dev_printk(dev
, KERN_WARNING
, "no PIO support\n");
3485 dev
->xfer_mode
= dev
->pio_mode
;
3486 dev
->xfer_shift
= ATA_SHIFT_PIO
;
3487 if (ap
->ops
->set_piomode
)
3488 ap
->ops
->set_piomode(ap
, dev
);
3491 /* step 3: set host DMA timings */
3492 ata_link_for_each_dev(dev
, link
) {
3493 if (!ata_dev_enabled(dev
) || dev
->dma_mode
== 0xff)
3496 dev
->xfer_mode
= dev
->dma_mode
;
3497 dev
->xfer_shift
= ata_xfer_mode2shift(dev
->dma_mode
);
3498 if (ap
->ops
->set_dmamode
)
3499 ap
->ops
->set_dmamode(ap
, dev
);
3502 /* step 4: update devices' xfer mode */
3503 ata_link_for_each_dev(dev
, link
) {
3504 /* don't update suspended devices' xfer mode */
3505 if (!ata_dev_enabled(dev
))
3508 rc
= ata_dev_set_mode(dev
);
3513 /* Record simplex status. If we selected DMA then the other
3514 * host channels are not permitted to do so.
3516 if (used_dma
&& (ap
->host
->flags
& ATA_HOST_SIMPLEX
))
3517 ap
->host
->simplex_claimed
= ap
;
3521 *r_failed_dev
= dev
;
3526 * ata_tf_to_host - issue ATA taskfile to host controller
3527 * @ap: port to which command is being issued
3528 * @tf: ATA taskfile register set
3530 * Issues ATA taskfile register set to ATA host controller,
3531 * with proper synchronization with interrupt handler and
3535 * spin_lock_irqsave(host lock)
3538 static inline void ata_tf_to_host(struct ata_port
*ap
,
3539 const struct ata_taskfile
*tf
)
3541 ap
->ops
->tf_load(ap
, tf
);
3542 ap
->ops
->exec_command(ap
, tf
);
3546 * ata_busy_sleep - sleep until BSY clears, or timeout
3547 * @ap: port containing status register to be polled
3548 * @tmout_pat: impatience timeout
3549 * @tmout: overall timeout
3551 * Sleep until ATA Status register bit BSY clears,
3552 * or a timeout occurs.
3555 * Kernel thread context (may sleep).
3558 * 0 on success, -errno otherwise.
3560 int ata_busy_sleep(struct ata_port
*ap
,
3561 unsigned long tmout_pat
, unsigned long tmout
)
3563 unsigned long timer_start
, timeout
;
3566 status
= ata_busy_wait(ap
, ATA_BUSY
, 300);
3567 timer_start
= jiffies
;
3568 timeout
= timer_start
+ tmout_pat
;
3569 while (status
!= 0xff && (status
& ATA_BUSY
) &&
3570 time_before(jiffies
, timeout
)) {
3572 status
= ata_busy_wait(ap
, ATA_BUSY
, 3);
3575 if (status
!= 0xff && (status
& ATA_BUSY
))
3576 ata_port_printk(ap
, KERN_WARNING
,
3577 "port is slow to respond, please be patient "
3578 "(Status 0x%x)\n", status
);
3580 timeout
= timer_start
+ tmout
;
3581 while (status
!= 0xff && (status
& ATA_BUSY
) &&
3582 time_before(jiffies
, timeout
)) {
3584 status
= ata_chk_status(ap
);
3590 if (status
& ATA_BUSY
) {
3591 ata_port_printk(ap
, KERN_ERR
, "port failed to respond "
3592 "(%lu secs, Status 0x%x)\n",
3593 tmout
/ HZ
, status
);
3601 * ata_wait_after_reset - wait before checking status after reset
3602 * @ap: port containing status register to be polled
3603 * @deadline: deadline jiffies for the operation
3605 * After reset, we need to pause a while before reading status.
3606 * Also, certain combination of controller and device report 0xff
3607 * for some duration (e.g. until SATA PHY is up and running)
3608 * which is interpreted as empty port in ATA world. This
3609 * function also waits for such devices to get out of 0xff
3613 * Kernel thread context (may sleep).
3615 void ata_wait_after_reset(struct ata_port
*ap
, unsigned long deadline
)
3617 unsigned long until
= jiffies
+ ATA_TMOUT_FF_WAIT
;
3619 if (time_before(until
, deadline
))
3622 /* Spec mandates ">= 2ms" before checking status. We wait
3623 * 150ms, because that was the magic delay used for ATAPI
3624 * devices in Hale Landis's ATADRVR, for the period of time
3625 * between when the ATA command register is written, and then
3626 * status is checked. Because waiting for "a while" before
3627 * checking status is fine, post SRST, we perform this magic
3628 * delay here as well.
3630 * Old drivers/ide uses the 2mS rule and then waits for ready.
3634 /* Wait for 0xff to clear. Some SATA devices take a long time
3635 * to clear 0xff after reset. For example, HHD424020F7SV00
3636 * iVDR needs >= 800ms while. Quantum GoVault needs even more
3639 * Note that some PATA controllers (pata_ali) explode if
3640 * status register is read more than once when there's no
3643 if (ap
->flags
& ATA_FLAG_SATA
) {
3645 u8 status
= ata_chk_status(ap
);
3647 if (status
!= 0xff || time_after(jiffies
, deadline
))
3656 * ata_wait_ready - sleep until BSY clears, or timeout
3657 * @ap: port containing status register to be polled
3658 * @deadline: deadline jiffies for the operation
3660 * Sleep until ATA Status register bit BSY clears, or timeout
3664 * Kernel thread context (may sleep).
3667 * 0 on success, -errno otherwise.
3669 int ata_wait_ready(struct ata_port
*ap
, unsigned long deadline
)
3671 unsigned long start
= jiffies
;
3675 u8 status
= ata_chk_status(ap
);
3676 unsigned long now
= jiffies
;
3678 if (!(status
& ATA_BUSY
))
3680 if (!ata_link_online(&ap
->link
) && status
== 0xff)
3682 if (time_after(now
, deadline
))
3685 if (!warned
&& time_after(now
, start
+ 5 * HZ
) &&
3686 (deadline
- now
> 3 * HZ
)) {
3687 ata_port_printk(ap
, KERN_WARNING
,
3688 "port is slow to respond, please be patient "
3689 "(Status 0x%x)\n", status
);
3697 static int ata_bus_post_reset(struct ata_port
*ap
, unsigned int devmask
,
3698 unsigned long deadline
)
3700 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3701 unsigned int dev0
= devmask
& (1 << 0);
3702 unsigned int dev1
= devmask
& (1 << 1);
3705 /* if device 0 was found in ata_devchk, wait for its
3709 rc
= ata_wait_ready(ap
, deadline
);
3717 /* if device 1 was found in ata_devchk, wait for register
3718 * access briefly, then wait for BSY to clear.
3723 ap
->ops
->dev_select(ap
, 1);
3725 /* Wait for register access. Some ATAPI devices fail
3726 * to set nsect/lbal after reset, so don't waste too
3727 * much time on it. We're gonna wait for !BSY anyway.
3729 for (i
= 0; i
< 2; i
++) {
3732 nsect
= ioread8(ioaddr
->nsect_addr
);
3733 lbal
= ioread8(ioaddr
->lbal_addr
);
3734 if ((nsect
== 1) && (lbal
== 1))
3736 msleep(50); /* give drive a breather */
3739 rc
= ata_wait_ready(ap
, deadline
);
3747 /* is all this really necessary? */
3748 ap
->ops
->dev_select(ap
, 0);
3750 ap
->ops
->dev_select(ap
, 1);
3752 ap
->ops
->dev_select(ap
, 0);
3757 static int ata_bus_softreset(struct ata_port
*ap
, unsigned int devmask
,
3758 unsigned long deadline
)
3760 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3762 DPRINTK("ata%u: bus reset via SRST\n", ap
->print_id
);
3764 /* software reset. causes dev0 to be selected */
3765 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3766 udelay(20); /* FIXME: flush */
3767 iowrite8(ap
->ctl
| ATA_SRST
, ioaddr
->ctl_addr
);
3768 udelay(20); /* FIXME: flush */
3769 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3771 /* wait a while before checking status */
3772 ata_wait_after_reset(ap
, deadline
);
3774 /* Before we perform post reset processing we want to see if
3775 * the bus shows 0xFF because the odd clown forgets the D7
3776 * pulldown resistor.
3778 if (ata_chk_status(ap
) == 0xFF)
3781 return ata_bus_post_reset(ap
, devmask
, deadline
);
3785 * ata_bus_reset - reset host port and associated ATA channel
3786 * @ap: port to reset
3788 * This is typically the first time we actually start issuing
3789 * commands to the ATA channel. We wait for BSY to clear, then
3790 * issue EXECUTE DEVICE DIAGNOSTIC command, polling for its
3791 * result. Determine what devices, if any, are on the channel
3792 * by looking at the device 0/1 error register. Look at the signature
3793 * stored in each device's taskfile registers, to determine if
3794 * the device is ATA or ATAPI.
3797 * PCI/etc. bus probe sem.
3798 * Obtains host lock.
3801 * Sets ATA_FLAG_DISABLED if bus reset fails.
3804 void ata_bus_reset(struct ata_port
*ap
)
3806 struct ata_device
*device
= ap
->link
.device
;
3807 struct ata_ioports
*ioaddr
= &ap
->ioaddr
;
3808 unsigned int slave_possible
= ap
->flags
& ATA_FLAG_SLAVE_POSS
;
3810 unsigned int dev0
, dev1
= 0, devmask
= 0;
3813 DPRINTK("ENTER, host %u, port %u\n", ap
->print_id
, ap
->port_no
);
3815 /* determine if device 0/1 are present */
3816 if (ap
->flags
& ATA_FLAG_SATA_RESET
)
3819 dev0
= ata_devchk(ap
, 0);
3821 dev1
= ata_devchk(ap
, 1);
3825 devmask
|= (1 << 0);
3827 devmask
|= (1 << 1);
3829 /* select device 0 again */
3830 ap
->ops
->dev_select(ap
, 0);
3832 /* issue bus reset */
3833 if (ap
->flags
& ATA_FLAG_SRST
) {
3834 rc
= ata_bus_softreset(ap
, devmask
, jiffies
+ 40 * HZ
);
3835 if (rc
&& rc
!= -ENODEV
)
3840 * determine by signature whether we have ATA or ATAPI devices
3842 device
[0].class = ata_dev_try_classify(&device
[0], dev0
, &err
);
3843 if ((slave_possible
) && (err
!= 0x81))
3844 device
[1].class = ata_dev_try_classify(&device
[1], dev1
, &err
);
3846 /* is double-select really necessary? */
3847 if (device
[1].class != ATA_DEV_NONE
)
3848 ap
->ops
->dev_select(ap
, 1);
3849 if (device
[0].class != ATA_DEV_NONE
)
3850 ap
->ops
->dev_select(ap
, 0);
3852 /* if no devices were detected, disable this port */
3853 if ((device
[0].class == ATA_DEV_NONE
) &&
3854 (device
[1].class == ATA_DEV_NONE
))
3857 if (ap
->flags
& (ATA_FLAG_SATA_RESET
| ATA_FLAG_SRST
)) {
3858 /* set up device control for ATA_FLAG_SATA_RESET */
3859 iowrite8(ap
->ctl
, ioaddr
->ctl_addr
);
3866 ata_port_printk(ap
, KERN_ERR
, "disabling port\n");
3867 ata_port_disable(ap
);
3873 * sata_link_debounce - debounce SATA phy status
3874 * @link: ATA link to debounce SATA phy status for
3875 * @params: timing parameters { interval, duratinon, timeout } in msec
3876 * @deadline: deadline jiffies for the operation
3878 * Make sure SStatus of @link reaches stable state, determined by
3879 * holding the same value where DET is not 1 for @duration polled
3880 * every @interval, before @timeout. Timeout constraints the
3881 * beginning of the stable state. Because DET gets stuck at 1 on
3882 * some controllers after hot unplugging, this functions waits
3883 * until timeout then returns 0 if DET is stable at 1.
3885 * @timeout is further limited by @deadline. The sooner of the
3889 * Kernel thread context (may sleep)
3892 * 0 on success, -errno on failure.
3894 int sata_link_debounce(struct ata_link
*link
, const unsigned long *params
,
3895 unsigned long deadline
)
3897 unsigned long interval_msec
= params
[0];
3898 unsigned long duration
= msecs_to_jiffies(params
[1]);
3899 unsigned long last_jiffies
, t
;
3903 t
= jiffies
+ msecs_to_jiffies(params
[2]);
3904 if (time_before(t
, deadline
))
3907 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
3912 last_jiffies
= jiffies
;
3915 msleep(interval_msec
);
3916 if ((rc
= sata_scr_read(link
, SCR_STATUS
, &cur
)))
3922 if (cur
== 1 && time_before(jiffies
, deadline
))
3924 if (time_after(jiffies
, last_jiffies
+ duration
))
3929 /* unstable, start over */
3931 last_jiffies
= jiffies
;
3933 /* Check deadline. If debouncing failed, return
3934 * -EPIPE to tell upper layer to lower link speed.
3936 if (time_after(jiffies
, deadline
))
3942 * sata_link_resume - resume SATA link
3943 * @link: ATA link to resume SATA
3944 * @params: timing parameters { interval, duratinon, timeout } in msec
3945 * @deadline: deadline jiffies for the operation
3947 * Resume SATA phy @link and debounce it.
3950 * Kernel thread context (may sleep)
3953 * 0 on success, -errno on failure.
3955 int sata_link_resume(struct ata_link
*link
, const unsigned long *params
,
3956 unsigned long deadline
)
3961 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
3964 scontrol
= (scontrol
& 0x0f0) | 0x300;
3966 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
3969 /* Some PHYs react badly if SStatus is pounded immediately
3970 * after resuming. Delay 200ms before debouncing.
3974 return sata_link_debounce(link
, params
, deadline
);
3978 * ata_std_prereset - prepare for reset
3979 * @link: ATA link to be reset
3980 * @deadline: deadline jiffies for the operation
3982 * @link is about to be reset. Initialize it. Failure from
3983 * prereset makes libata abort whole reset sequence and give up
3984 * that port, so prereset should be best-effort. It does its
3985 * best to prepare for reset sequence but if things go wrong, it
3986 * should just whine, not fail.
3989 * Kernel thread context (may sleep)
3992 * 0 on success, -errno otherwise.
3994 int ata_std_prereset(struct ata_link
*link
, unsigned long deadline
)
3996 struct ata_port
*ap
= link
->ap
;
3997 struct ata_eh_context
*ehc
= &link
->eh_context
;
3998 const unsigned long *timing
= sata_ehc_deb_timing(ehc
);
4001 /* if we're about to do hardreset, nothing more to do */
4002 if (ehc
->i
.action
& ATA_EH_HARDRESET
)
4005 /* if SATA, resume link */
4006 if (ap
->flags
& ATA_FLAG_SATA
) {
4007 rc
= sata_link_resume(link
, timing
, deadline
);
4008 /* whine about phy resume failure but proceed */
4009 if (rc
&& rc
!= -EOPNOTSUPP
)
4010 ata_link_printk(link
, KERN_WARNING
, "failed to resume "
4011 "link for reset (errno=%d)\n", rc
);
4014 /* wait for !BSY if we don't know that no device is attached */
4015 if (!ata_link_offline(link
)) {
4016 rc
= ata_wait_ready(ap
, deadline
);
4017 if (rc
&& rc
!= -ENODEV
) {
4018 ata_link_printk(link
, KERN_WARNING
, "device not ready "
4019 "(errno=%d), forcing hardreset\n", rc
);
4020 ehc
->i
.action
|= ATA_EH_HARDRESET
;
4028 * ata_std_softreset - reset host port via ATA SRST
4029 * @link: ATA link to reset
4030 * @classes: resulting classes of attached devices
4031 * @deadline: deadline jiffies for the operation
4033 * Reset host port using ATA SRST.
4036 * Kernel thread context (may sleep)
4039 * 0 on success, -errno otherwise.
4041 int ata_std_softreset(struct ata_link
*link
, unsigned int *classes
,
4042 unsigned long deadline
)
4044 struct ata_port
*ap
= link
->ap
;
4045 unsigned int slave_possible
= ap
->flags
& ATA_FLAG_SLAVE_POSS
;
4046 unsigned int devmask
= 0;
4052 if (ata_link_offline(link
)) {
4053 classes
[0] = ATA_DEV_NONE
;
4057 /* determine if device 0/1 are present */
4058 if (ata_devchk(ap
, 0))
4059 devmask
|= (1 << 0);
4060 if (slave_possible
&& ata_devchk(ap
, 1))
4061 devmask
|= (1 << 1);
4063 /* select device 0 again */
4064 ap
->ops
->dev_select(ap
, 0);
4066 /* issue bus reset */
4067 DPRINTK("about to softreset, devmask=%x\n", devmask
);
4068 rc
= ata_bus_softreset(ap
, devmask
, deadline
);
4069 /* if link is occupied, -ENODEV too is an error */
4070 if (rc
&& (rc
!= -ENODEV
|| sata_scr_valid(link
))) {
4071 ata_link_printk(link
, KERN_ERR
, "SRST failed (errno=%d)\n", rc
);
4075 /* determine by signature whether we have ATA or ATAPI devices */
4076 classes
[0] = ata_dev_try_classify(&link
->device
[0],
4077 devmask
& (1 << 0), &err
);
4078 if (slave_possible
&& err
!= 0x81)
4079 classes
[1] = ata_dev_try_classify(&link
->device
[1],
4080 devmask
& (1 << 1), &err
);
4083 DPRINTK("EXIT, classes[0]=%u [1]=%u\n", classes
[0], classes
[1]);
4088 * sata_link_hardreset - reset link via SATA phy reset
4089 * @link: link to reset
4090 * @timing: timing parameters { interval, duratinon, timeout } in msec
4091 * @deadline: deadline jiffies for the operation
4093 * SATA phy-reset @link using DET bits of SControl register.
4096 * Kernel thread context (may sleep)
4099 * 0 on success, -errno otherwise.
4101 int sata_link_hardreset(struct ata_link
*link
, const unsigned long *timing
,
4102 unsigned long deadline
)
4109 if (sata_set_spd_needed(link
)) {
4110 /* SATA spec says nothing about how to reconfigure
4111 * spd. To be on the safe side, turn off phy during
4112 * reconfiguration. This works for at least ICH7 AHCI
4115 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
4118 scontrol
= (scontrol
& 0x0f0) | 0x304;
4120 if ((rc
= sata_scr_write(link
, SCR_CONTROL
, scontrol
)))
4126 /* issue phy wake/reset */
4127 if ((rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
)))
4130 scontrol
= (scontrol
& 0x0f0) | 0x301;
4132 if ((rc
= sata_scr_write_flush(link
, SCR_CONTROL
, scontrol
)))
4135 /* Couldn't find anything in SATA I/II specs, but AHCI-1.1
4136 * 10.4.2 says at least 1 ms.
4140 /* bring link back */
4141 rc
= sata_link_resume(link
, timing
, deadline
);
4143 DPRINTK("EXIT, rc=%d\n", rc
);
4148 * sata_std_hardreset - reset host port via SATA phy reset
4149 * @link: link to reset
4150 * @class: resulting class of attached device
4151 * @deadline: deadline jiffies for the operation
4153 * SATA phy-reset host port using DET bits of SControl register,
4154 * wait for !BSY and classify the attached device.
4157 * Kernel thread context (may sleep)
4160 * 0 on success, -errno otherwise.
4162 int sata_std_hardreset(struct ata_link
*link
, unsigned int *class,
4163 unsigned long deadline
)
4165 struct ata_port
*ap
= link
->ap
;
4166 const unsigned long *timing
= sata_ehc_deb_timing(&link
->eh_context
);
4172 rc
= sata_link_hardreset(link
, timing
, deadline
);
4174 ata_link_printk(link
, KERN_ERR
,
4175 "COMRESET failed (errno=%d)\n", rc
);
4179 /* TODO: phy layer with polling, timeouts, etc. */
4180 if (ata_link_offline(link
)) {
4181 *class = ATA_DEV_NONE
;
4182 DPRINTK("EXIT, link offline\n");
4186 /* wait a while before checking status */
4187 ata_wait_after_reset(ap
, deadline
);
4189 /* If PMP is supported, we have to do follow-up SRST. Note
4190 * that some PMPs don't send D2H Reg FIS after hardreset at
4191 * all if the first port is empty. Wait for it just for a
4192 * second and request follow-up SRST.
4194 if (ap
->flags
& ATA_FLAG_PMP
) {
4195 ata_wait_ready(ap
, jiffies
+ HZ
);
4199 rc
= ata_wait_ready(ap
, deadline
);
4200 /* link occupied, -ENODEV too is an error */
4202 ata_link_printk(link
, KERN_ERR
,
4203 "COMRESET failed (errno=%d)\n", rc
);
4207 ap
->ops
->dev_select(ap
, 0); /* probably unnecessary */
4209 *class = ata_dev_try_classify(link
->device
, 1, NULL
);
4211 DPRINTK("EXIT, class=%u\n", *class);
4216 * ata_std_postreset - standard postreset callback
4217 * @link: the target ata_link
4218 * @classes: classes of attached devices
4220 * This function is invoked after a successful reset. Note that
4221 * the device might have been reset more than once using
4222 * different reset methods before postreset is invoked.
4225 * Kernel thread context (may sleep)
4227 void ata_std_postreset(struct ata_link
*link
, unsigned int *classes
)
4229 struct ata_port
*ap
= link
->ap
;
4234 /* print link status */
4235 sata_print_link_status(link
);
4238 if (sata_scr_read(link
, SCR_ERROR
, &serror
) == 0)
4239 sata_scr_write(link
, SCR_ERROR
, serror
);
4240 link
->eh_info
.serror
= 0;
4242 /* is double-select really necessary? */
4243 if (classes
[0] != ATA_DEV_NONE
)
4244 ap
->ops
->dev_select(ap
, 1);
4245 if (classes
[1] != ATA_DEV_NONE
)
4246 ap
->ops
->dev_select(ap
, 0);
4248 /* bail out if no device is present */
4249 if (classes
[0] == ATA_DEV_NONE
&& classes
[1] == ATA_DEV_NONE
) {
4250 DPRINTK("EXIT, no device\n");
4254 /* set up device control */
4255 if (ap
->ioaddr
.ctl_addr
)
4256 iowrite8(ap
->ctl
, ap
->ioaddr
.ctl_addr
);
4262 * ata_dev_same_device - Determine whether new ID matches configured device
4263 * @dev: device to compare against
4264 * @new_class: class of the new device
4265 * @new_id: IDENTIFY page of the new device
4267 * Compare @new_class and @new_id against @dev and determine
4268 * whether @dev is the device indicated by @new_class and
4275 * 1 if @dev matches @new_class and @new_id, 0 otherwise.
4277 static int ata_dev_same_device(struct ata_device
*dev
, unsigned int new_class
,
4280 const u16
*old_id
= dev
->id
;
4281 unsigned char model
[2][ATA_ID_PROD_LEN
+ 1];
4282 unsigned char serial
[2][ATA_ID_SERNO_LEN
+ 1];
4284 if (dev
->class != new_class
) {
4285 ata_dev_printk(dev
, KERN_INFO
, "class mismatch %d != %d\n",
4286 dev
->class, new_class
);
4290 ata_id_c_string(old_id
, model
[0], ATA_ID_PROD
, sizeof(model
[0]));
4291 ata_id_c_string(new_id
, model
[1], ATA_ID_PROD
, sizeof(model
[1]));
4292 ata_id_c_string(old_id
, serial
[0], ATA_ID_SERNO
, sizeof(serial
[0]));
4293 ata_id_c_string(new_id
, serial
[1], ATA_ID_SERNO
, sizeof(serial
[1]));
4295 if (strcmp(model
[0], model
[1])) {
4296 ata_dev_printk(dev
, KERN_INFO
, "model number mismatch "
4297 "'%s' != '%s'\n", model
[0], model
[1]);
4301 if (strcmp(serial
[0], serial
[1])) {
4302 ata_dev_printk(dev
, KERN_INFO
, "serial number mismatch "
4303 "'%s' != '%s'\n", serial
[0], serial
[1]);
4311 * ata_dev_reread_id - Re-read IDENTIFY data
4312 * @dev: target ATA device
4313 * @readid_flags: read ID flags
4315 * Re-read IDENTIFY page and make sure @dev is still attached to
4319 * Kernel thread context (may sleep)
4322 * 0 on success, negative errno otherwise
4324 int ata_dev_reread_id(struct ata_device
*dev
, unsigned int readid_flags
)
4326 unsigned int class = dev
->class;
4327 u16
*id
= (void *)dev
->link
->ap
->sector_buf
;
4331 rc
= ata_dev_read_id(dev
, &class, readid_flags
, id
);
4335 /* is the device still there? */
4336 if (!ata_dev_same_device(dev
, class, id
))
4339 memcpy(dev
->id
, id
, sizeof(id
[0]) * ATA_ID_WORDS
);
4344 * ata_dev_revalidate - Revalidate ATA device
4345 * @dev: device to revalidate
4346 * @new_class: new class code
4347 * @readid_flags: read ID flags
4349 * Re-read IDENTIFY page, make sure @dev is still attached to the
4350 * port and reconfigure it according to the new IDENTIFY page.
4353 * Kernel thread context (may sleep)
4356 * 0 on success, negative errno otherwise
4358 int ata_dev_revalidate(struct ata_device
*dev
, unsigned int new_class
,
4359 unsigned int readid_flags
)
4361 u64 n_sectors
= dev
->n_sectors
;
4364 if (!ata_dev_enabled(dev
))
4367 /* fail early if !ATA && !ATAPI to avoid issuing [P]IDENTIFY to PMP */
4368 if (ata_class_enabled(new_class
) &&
4369 new_class
!= ATA_DEV_ATA
&& new_class
!= ATA_DEV_ATAPI
) {
4370 ata_dev_printk(dev
, KERN_INFO
, "class mismatch %u != %u\n",
4371 dev
->class, new_class
);
4377 rc
= ata_dev_reread_id(dev
, readid_flags
);
4381 /* configure device according to the new ID */
4382 rc
= ata_dev_configure(dev
);
4386 /* verify n_sectors hasn't changed */
4387 if (dev
->class == ATA_DEV_ATA
&& n_sectors
&&
4388 dev
->n_sectors
!= n_sectors
) {
4389 ata_dev_printk(dev
, KERN_INFO
, "n_sectors mismatch "
4391 (unsigned long long)n_sectors
,
4392 (unsigned long long)dev
->n_sectors
);
4394 /* restore original n_sectors */
4395 dev
->n_sectors
= n_sectors
;
4404 ata_dev_printk(dev
, KERN_ERR
, "revalidation failed (errno=%d)\n", rc
);
4408 struct ata_blacklist_entry
{
4409 const char *model_num
;
4410 const char *model_rev
;
4411 unsigned long horkage
;
4414 static const struct ata_blacklist_entry ata_device_blacklist
[] = {
4415 /* Devices with DMA related problems under Linux */
4416 { "WDC AC11000H", NULL
, ATA_HORKAGE_NODMA
},
4417 { "WDC AC22100H", NULL
, ATA_HORKAGE_NODMA
},
4418 { "WDC AC32500H", NULL
, ATA_HORKAGE_NODMA
},
4419 { "WDC AC33100H", NULL
, ATA_HORKAGE_NODMA
},
4420 { "WDC AC31600H", NULL
, ATA_HORKAGE_NODMA
},
4421 { "WDC AC32100H", "24.09P07", ATA_HORKAGE_NODMA
},
4422 { "WDC AC23200L", "21.10N21", ATA_HORKAGE_NODMA
},
4423 { "Compaq CRD-8241B", NULL
, ATA_HORKAGE_NODMA
},
4424 { "CRD-8400B", NULL
, ATA_HORKAGE_NODMA
},
4425 { "CRD-8480B", NULL
, ATA_HORKAGE_NODMA
},
4426 { "CRD-8482B", NULL
, ATA_HORKAGE_NODMA
},
4427 { "CRD-84", NULL
, ATA_HORKAGE_NODMA
},
4428 { "SanDisk SDP3B", NULL
, ATA_HORKAGE_NODMA
},
4429 { "SanDisk SDP3B-64", NULL
, ATA_HORKAGE_NODMA
},
4430 { "SANYO CD-ROM CRD", NULL
, ATA_HORKAGE_NODMA
},
4431 { "HITACHI CDR-8", NULL
, ATA_HORKAGE_NODMA
},
4432 { "HITACHI CDR-8335", NULL
, ATA_HORKAGE_NODMA
},
4433 { "HITACHI CDR-8435", NULL
, ATA_HORKAGE_NODMA
},
4434 { "Toshiba CD-ROM XM-6202B", NULL
, ATA_HORKAGE_NODMA
},
4435 { "TOSHIBA CD-ROM XM-1702BC", NULL
, ATA_HORKAGE_NODMA
},
4436 { "CD-532E-A", NULL
, ATA_HORKAGE_NODMA
},
4437 { "E-IDE CD-ROM CR-840",NULL
, ATA_HORKAGE_NODMA
},
4438 { "CD-ROM Drive/F5A", NULL
, ATA_HORKAGE_NODMA
},
4439 { "WPI CDD-820", NULL
, ATA_HORKAGE_NODMA
},
4440 { "SAMSUNG CD-ROM SC-148C", NULL
, ATA_HORKAGE_NODMA
},
4441 { "SAMSUNG CD-ROM SC", NULL
, ATA_HORKAGE_NODMA
},
4442 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL
,ATA_HORKAGE_NODMA
},
4443 { "_NEC DV5800A", NULL
, ATA_HORKAGE_NODMA
},
4444 { "SAMSUNG CD-ROM SN-124", "N001", ATA_HORKAGE_NODMA
},
4445 { "Seagate STT20000A", NULL
, ATA_HORKAGE_NODMA
},
4446 /* Odd clown on sil3726/4726 PMPs */
4447 { "Config Disk", NULL
, ATA_HORKAGE_NODMA
|
4448 ATA_HORKAGE_SKIP_PM
},
4450 /* Weird ATAPI devices */
4451 { "TORiSAN DVD-ROM DRD-N216", NULL
, ATA_HORKAGE_MAX_SEC_128
},
4453 /* Devices we expect to fail diagnostics */
4455 /* Devices where NCQ should be avoided */
4457 { "WDC WD740ADFD-00", NULL
, ATA_HORKAGE_NONCQ
},
4458 { "WDC WD740ADFD-00NLR1", NULL
, ATA_HORKAGE_NONCQ
, },
4459 /* http://thread.gmane.org/gmane.linux.ide/14907 */
4460 { "FUJITSU MHT2060BH", NULL
, ATA_HORKAGE_NONCQ
},
4462 { "Maxtor *", "BANC*", ATA_HORKAGE_NONCQ
},
4463 { "Maxtor 7V300F0", "VA111630", ATA_HORKAGE_NONCQ
},
4464 { "ST380817AS", "3.42", ATA_HORKAGE_NONCQ
},
4465 { "ST3160023AS", "3.42", ATA_HORKAGE_NONCQ
},
4467 /* Blacklist entries taken from Silicon Image 3124/3132
4468 Windows driver .inf file - also several Linux problem reports */
4469 { "HTS541060G9SA00", "MB3OC60D", ATA_HORKAGE_NONCQ
, },
4470 { "HTS541080G9SA00", "MB4OC60D", ATA_HORKAGE_NONCQ
, },
4471 { "HTS541010G9SA00", "MBZOC60D", ATA_HORKAGE_NONCQ
, },
4473 /* devices which puke on READ_NATIVE_MAX */
4474 { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA
, },
4475 { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA
},
4476 { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA
},
4477 { "MAXTOR 6L080L4", "A93.0500", ATA_HORKAGE_BROKEN_HPA
},
4479 /* Devices which report 1 sector over size HPA */
4480 { "ST340823A", NULL
, ATA_HORKAGE_HPA_SIZE
, },
4481 { "ST320413A", NULL
, ATA_HORKAGE_HPA_SIZE
, },
4482 { "ST310211A", NULL
, ATA_HORKAGE_HPA_SIZE
, },
4484 /* Devices which get the IVB wrong */
4485 { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB
, },
4486 { "TSSTcorp CDDVDW SH-S202J", "SB00", ATA_HORKAGE_IVB
, },
4487 { "TSSTcorp CDDVDW SH-S202J", "SB01", ATA_HORKAGE_IVB
, },
4488 { "TSSTcorp CDDVDW SH-S202N", "SB00", ATA_HORKAGE_IVB
, },
4489 { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB
, },
4495 static int strn_pattern_cmp(const char *patt
, const char *name
, int wildchar
)
4501 * check for trailing wildcard: *\0
4503 p
= strchr(patt
, wildchar
);
4504 if (p
&& ((*(p
+ 1)) == 0))
4515 return strncmp(patt
, name
, len
);
4518 static unsigned long ata_dev_blacklisted(const struct ata_device
*dev
)
4520 unsigned char model_num
[ATA_ID_PROD_LEN
+ 1];
4521 unsigned char model_rev
[ATA_ID_FW_REV_LEN
+ 1];
4522 const struct ata_blacklist_entry
*ad
= ata_device_blacklist
;
4524 ata_id_c_string(dev
->id
, model_num
, ATA_ID_PROD
, sizeof(model_num
));
4525 ata_id_c_string(dev
->id
, model_rev
, ATA_ID_FW_REV
, sizeof(model_rev
));
4527 while (ad
->model_num
) {
4528 if (!strn_pattern_cmp(ad
->model_num
, model_num
, '*')) {
4529 if (ad
->model_rev
== NULL
)
4531 if (!strn_pattern_cmp(ad
->model_rev
, model_rev
, '*'))
4539 static int ata_dma_blacklisted(const struct ata_device
*dev
)
4541 /* We don't support polling DMA.
4542 * DMA blacklist those ATAPI devices with CDB-intr (and use PIO)
4543 * if the LLDD handles only interrupts in the HSM_ST_LAST state.
4545 if ((dev
->link
->ap
->flags
& ATA_FLAG_PIO_POLLING
) &&
4546 (dev
->flags
& ATA_DFLAG_CDB_INTR
))
4548 return (dev
->horkage
& ATA_HORKAGE_NODMA
) ? 1 : 0;
4552 * ata_is_40wire - check drive side detection
4555 * Perform drive side detection decoding, allowing for device vendors
4556 * who can't follow the documentation.
4559 static int ata_is_40wire(struct ata_device
*dev
)
4561 if (dev
->horkage
& ATA_HORKAGE_IVB
)
4562 return ata_drive_40wire_relaxed(dev
->id
);
4563 return ata_drive_40wire(dev
->id
);
4567 * ata_dev_xfermask - Compute supported xfermask of the given device
4568 * @dev: Device to compute xfermask for
4570 * Compute supported xfermask of @dev and store it in
4571 * dev->*_mask. This function is responsible for applying all
4572 * known limits including host controller limits, device
4578 static void ata_dev_xfermask(struct ata_device
*dev
)
4580 struct ata_link
*link
= dev
->link
;
4581 struct ata_port
*ap
= link
->ap
;
4582 struct ata_host
*host
= ap
->host
;
4583 unsigned long xfer_mask
;
4585 /* controller modes available */
4586 xfer_mask
= ata_pack_xfermask(ap
->pio_mask
,
4587 ap
->mwdma_mask
, ap
->udma_mask
);
4589 /* drive modes available */
4590 xfer_mask
&= ata_pack_xfermask(dev
->pio_mask
,
4591 dev
->mwdma_mask
, dev
->udma_mask
);
4592 xfer_mask
&= ata_id_xfermask(dev
->id
);
4595 * CFA Advanced TrueIDE timings are not allowed on a shared
4598 if (ata_dev_pair(dev
)) {
4599 /* No PIO5 or PIO6 */
4600 xfer_mask
&= ~(0x03 << (ATA_SHIFT_PIO
+ 5));
4601 /* No MWDMA3 or MWDMA 4 */
4602 xfer_mask
&= ~(0x03 << (ATA_SHIFT_MWDMA
+ 3));
4605 if (ata_dma_blacklisted(dev
)) {
4606 xfer_mask
&= ~(ATA_MASK_MWDMA
| ATA_MASK_UDMA
);
4607 ata_dev_printk(dev
, KERN_WARNING
,
4608 "device is on DMA blacklist, disabling DMA\n");
4611 if ((host
->flags
& ATA_HOST_SIMPLEX
) &&
4612 host
->simplex_claimed
&& host
->simplex_claimed
!= ap
) {
4613 xfer_mask
&= ~(ATA_MASK_MWDMA
| ATA_MASK_UDMA
);
4614 ata_dev_printk(dev
, KERN_WARNING
, "simplex DMA is claimed by "
4615 "other device, disabling DMA\n");
4618 if (ap
->flags
& ATA_FLAG_NO_IORDY
)
4619 xfer_mask
&= ata_pio_mask_no_iordy(dev
);
4621 if (ap
->ops
->mode_filter
)
4622 xfer_mask
= ap
->ops
->mode_filter(dev
, xfer_mask
);
4624 /* Apply cable rule here. Don't apply it early because when
4625 * we handle hot plug the cable type can itself change.
4626 * Check this last so that we know if the transfer rate was
4627 * solely limited by the cable.
4628 * Unknown or 80 wire cables reported host side are checked
4629 * drive side as well. Cases where we know a 40wire cable
4630 * is used safely for 80 are not checked here.
4632 if (xfer_mask
& (0xF8 << ATA_SHIFT_UDMA
))
4633 /* UDMA/44 or higher would be available */
4634 if ((ap
->cbl
== ATA_CBL_PATA40
) ||
4635 (ata_is_40wire(dev
) &&
4636 (ap
->cbl
== ATA_CBL_PATA_UNK
||
4637 ap
->cbl
== ATA_CBL_PATA80
))) {
4638 ata_dev_printk(dev
, KERN_WARNING
,
4639 "limited to UDMA/33 due to 40-wire cable\n");
4640 xfer_mask
&= ~(0xF8 << ATA_SHIFT_UDMA
);
4643 ata_unpack_xfermask(xfer_mask
, &dev
->pio_mask
,
4644 &dev
->mwdma_mask
, &dev
->udma_mask
);
4648 * ata_dev_set_xfermode - Issue SET FEATURES - XFER MODE command
4649 * @dev: Device to which command will be sent
4651 * Issue SET FEATURES - XFER MODE command to device @dev
4655 * PCI/etc. bus probe sem.
4658 * 0 on success, AC_ERR_* mask otherwise.
4661 static unsigned int ata_dev_set_xfermode(struct ata_device
*dev
)
4663 struct ata_taskfile tf
;
4664 unsigned int err_mask
;
4666 /* set up set-features taskfile */
4667 DPRINTK("set features - xfer mode\n");
4669 /* Some controllers and ATAPI devices show flaky interrupt
4670 * behavior after setting xfer mode. Use polling instead.
4672 ata_tf_init(dev
, &tf
);
4673 tf
.command
= ATA_CMD_SET_FEATURES
;
4674 tf
.feature
= SETFEATURES_XFER
;
4675 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
| ATA_TFLAG_POLLING
;
4676 tf
.protocol
= ATA_PROT_NODATA
;
4677 /* If we are using IORDY we must send the mode setting command */
4678 if (ata_pio_need_iordy(dev
))
4679 tf
.nsect
= dev
->xfer_mode
;
4680 /* If the device has IORDY and the controller does not - turn it off */
4681 else if (ata_id_has_iordy(dev
->id
))
4683 else /* In the ancient relic department - skip all of this */
4686 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
4688 DPRINTK("EXIT, err_mask=%x\n", err_mask
);
4692 * ata_dev_set_feature - Issue SET FEATURES - SATA FEATURES
4693 * @dev: Device to which command will be sent
4694 * @enable: Whether to enable or disable the feature
4695 * @feature: The sector count represents the feature to set
4697 * Issue SET FEATURES - SATA FEATURES command to device @dev
4698 * on port @ap with sector count
4701 * PCI/etc. bus probe sem.
4704 * 0 on success, AC_ERR_* mask otherwise.
4706 static unsigned int ata_dev_set_feature(struct ata_device
*dev
, u8 enable
,
4709 struct ata_taskfile tf
;
4710 unsigned int err_mask
;
4712 /* set up set-features taskfile */
4713 DPRINTK("set features - SATA features\n");
4715 ata_tf_init(dev
, &tf
);
4716 tf
.command
= ATA_CMD_SET_FEATURES
;
4717 tf
.feature
= enable
;
4718 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
4719 tf
.protocol
= ATA_PROT_NODATA
;
4722 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
4724 DPRINTK("EXIT, err_mask=%x\n", err_mask
);
4729 * ata_dev_init_params - Issue INIT DEV PARAMS command
4730 * @dev: Device to which command will be sent
4731 * @heads: Number of heads (taskfile parameter)
4732 * @sectors: Number of sectors (taskfile parameter)
4735 * Kernel thread context (may sleep)
4738 * 0 on success, AC_ERR_* mask otherwise.
4740 static unsigned int ata_dev_init_params(struct ata_device
*dev
,
4741 u16 heads
, u16 sectors
)
4743 struct ata_taskfile tf
;
4744 unsigned int err_mask
;
4746 /* Number of sectors per track 1-255. Number of heads 1-16 */
4747 if (sectors
< 1 || sectors
> 255 || heads
< 1 || heads
> 16)
4748 return AC_ERR_INVALID
;
4750 /* set up init dev params taskfile */
4751 DPRINTK("init dev params \n");
4753 ata_tf_init(dev
, &tf
);
4754 tf
.command
= ATA_CMD_INIT_DEV_PARAMS
;
4755 tf
.flags
|= ATA_TFLAG_ISADDR
| ATA_TFLAG_DEVICE
;
4756 tf
.protocol
= ATA_PROT_NODATA
;
4758 tf
.device
|= (heads
- 1) & 0x0f; /* max head = num. of heads - 1 */
4760 err_mask
= ata_exec_internal(dev
, &tf
, NULL
, DMA_NONE
, NULL
, 0, 0);
4761 /* A clean abort indicates an original or just out of spec drive
4762 and we should continue as we issue the setup based on the
4763 drive reported working geometry */
4764 if (err_mask
== AC_ERR_DEV
&& (tf
.feature
& ATA_ABORTED
))
4767 DPRINTK("EXIT, err_mask=%x\n", err_mask
);
4772 * ata_sg_clean - Unmap DMA memory associated with command
4773 * @qc: Command containing DMA memory to be released
4775 * Unmap all mapped DMA memory associated with this command.
4778 * spin_lock_irqsave(host lock)
4780 void ata_sg_clean(struct ata_queued_cmd
*qc
)
4782 struct ata_port
*ap
= qc
->ap
;
4783 struct scatterlist
*sg
= qc
->sg
;
4784 int dir
= qc
->dma_dir
;
4786 WARN_ON(sg
== NULL
);
4788 VPRINTK("unmapping %u sg elements\n", qc
->n_elem
);
4791 dma_unmap_sg(ap
->dev
, sg
, qc
->n_elem
, dir
);
4793 qc
->flags
&= ~ATA_QCFLAG_DMAMAP
;
4798 * ata_fill_sg - Fill PCI IDE PRD table
4799 * @qc: Metadata associated with taskfile to be transferred
4801 * Fill PCI IDE PRD (scatter-gather) table with segments
4802 * associated with the current disk command.
4805 * spin_lock_irqsave(host lock)
4808 static void ata_fill_sg(struct ata_queued_cmd
*qc
)
4810 struct ata_port
*ap
= qc
->ap
;
4811 struct scatterlist
*sg
;
4812 unsigned int si
, pi
;
4815 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
4819 /* determine if physical DMA addr spans 64K boundary.
4820 * Note h/w doesn't support 64-bit, so we unconditionally
4821 * truncate dma_addr_t to u32.
4823 addr
= (u32
) sg_dma_address(sg
);
4824 sg_len
= sg_dma_len(sg
);
4827 offset
= addr
& 0xffff;
4829 if ((offset
+ sg_len
) > 0x10000)
4830 len
= 0x10000 - offset
;
4832 ap
->prd
[pi
].addr
= cpu_to_le32(addr
);
4833 ap
->prd
[pi
].flags_len
= cpu_to_le32(len
& 0xffff);
4834 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi
, addr
, len
);
4842 ap
->prd
[pi
- 1].flags_len
|= cpu_to_le32(ATA_PRD_EOT
);
4846 * ata_fill_sg_dumb - Fill PCI IDE PRD table
4847 * @qc: Metadata associated with taskfile to be transferred
4849 * Fill PCI IDE PRD (scatter-gather) table with segments
4850 * associated with the current disk command. Perform the fill
4851 * so that we avoid writing any length 64K records for
4852 * controllers that don't follow the spec.
4855 * spin_lock_irqsave(host lock)
4858 static void ata_fill_sg_dumb(struct ata_queued_cmd
*qc
)
4860 struct ata_port
*ap
= qc
->ap
;
4861 struct scatterlist
*sg
;
4862 unsigned int si
, pi
;
4865 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
4867 u32 sg_len
, len
, blen
;
4869 /* determine if physical DMA addr spans 64K boundary.
4870 * Note h/w doesn't support 64-bit, so we unconditionally
4871 * truncate dma_addr_t to u32.
4873 addr
= (u32
) sg_dma_address(sg
);
4874 sg_len
= sg_dma_len(sg
);
4877 offset
= addr
& 0xffff;
4879 if ((offset
+ sg_len
) > 0x10000)
4880 len
= 0x10000 - offset
;
4882 blen
= len
& 0xffff;
4883 ap
->prd
[pi
].addr
= cpu_to_le32(addr
);
4885 /* Some PATA chipsets like the CS5530 can't
4886 cope with 0x0000 meaning 64K as the spec says */
4887 ap
->prd
[pi
].flags_len
= cpu_to_le32(0x8000);
4889 ap
->prd
[++pi
].addr
= cpu_to_le32(addr
+ 0x8000);
4891 ap
->prd
[pi
].flags_len
= cpu_to_le32(blen
);
4892 VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi
, addr
, len
);
4900 ap
->prd
[pi
- 1].flags_len
|= cpu_to_le32(ATA_PRD_EOT
);
4904 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported
4905 * @qc: Metadata associated with taskfile to check
4907 * Allow low-level driver to filter ATA PACKET commands, returning
4908 * a status indicating whether or not it is OK to use DMA for the
4909 * supplied PACKET command.
4912 * spin_lock_irqsave(host lock)
4914 * RETURNS: 0 when ATAPI DMA can be used
4917 int ata_check_atapi_dma(struct ata_queued_cmd
*qc
)
4919 struct ata_port
*ap
= qc
->ap
;
4921 /* Don't allow DMA if it isn't multiple of 16 bytes. Quite a
4922 * few ATAPI devices choke on such DMA requests.
4924 if (unlikely(qc
->nbytes
& 15))
4927 if (ap
->ops
->check_atapi_dma
)
4928 return ap
->ops
->check_atapi_dma(qc
);
4934 * ata_std_qc_defer - Check whether a qc needs to be deferred
4935 * @qc: ATA command in question
4937 * Non-NCQ commands cannot run with any other command, NCQ or
4938 * not. As upper layer only knows the queue depth, we are
4939 * responsible for maintaining exclusion. This function checks
4940 * whether a new command @qc can be issued.
4943 * spin_lock_irqsave(host lock)
4946 * ATA_DEFER_* if deferring is needed, 0 otherwise.
4948 int ata_std_qc_defer(struct ata_queued_cmd
*qc
)
4950 struct ata_link
*link
= qc
->dev
->link
;
4952 if (qc
->tf
.protocol
== ATA_PROT_NCQ
) {
4953 if (!ata_tag_valid(link
->active_tag
))
4956 if (!ata_tag_valid(link
->active_tag
) && !link
->sactive
)
4960 return ATA_DEFER_LINK
;
4964 * ata_qc_prep - Prepare taskfile for submission
4965 * @qc: Metadata associated with taskfile to be prepared
4967 * Prepare ATA taskfile for submission.
4970 * spin_lock_irqsave(host lock)
4972 void ata_qc_prep(struct ata_queued_cmd
*qc
)
4974 if (!(qc
->flags
& ATA_QCFLAG_DMAMAP
))
4981 * ata_dumb_qc_prep - Prepare taskfile for submission
4982 * @qc: Metadata associated with taskfile to be prepared
4984 * Prepare ATA taskfile for submission.
4987 * spin_lock_irqsave(host lock)
4989 void ata_dumb_qc_prep(struct ata_queued_cmd
*qc
)
4991 if (!(qc
->flags
& ATA_QCFLAG_DMAMAP
))
4994 ata_fill_sg_dumb(qc
);
4997 void ata_noop_qc_prep(struct ata_queued_cmd
*qc
) { }
5000 * ata_sg_init - Associate command with scatter-gather table.
5001 * @qc: Command to be associated
5002 * @sg: Scatter-gather table.
5003 * @n_elem: Number of elements in s/g table.
5005 * Initialize the data-related elements of queued_cmd @qc
5006 * to point to a scatter-gather table @sg, containing @n_elem
5010 * spin_lock_irqsave(host lock)
5012 void ata_sg_init(struct ata_queued_cmd
*qc
, struct scatterlist
*sg
,
5013 unsigned int n_elem
)
5016 qc
->n_elem
= n_elem
;
5021 * ata_sg_setup - DMA-map the scatter-gather table associated with a command.
5022 * @qc: Command with scatter-gather table to be mapped.
5024 * DMA-map the scatter-gather table associated with queued_cmd @qc.
5027 * spin_lock_irqsave(host lock)
5030 * Zero on success, negative on error.
5033 static int ata_sg_setup(struct ata_queued_cmd
*qc
)
5035 struct ata_port
*ap
= qc
->ap
;
5036 unsigned int n_elem
;
5038 VPRINTK("ENTER, ata%u\n", ap
->print_id
);
5040 n_elem
= dma_map_sg(ap
->dev
, qc
->sg
, qc
->n_elem
, qc
->dma_dir
);
5044 DPRINTK("%d sg elements mapped\n", n_elem
);
5046 qc
->n_elem
= n_elem
;
5047 qc
->flags
|= ATA_QCFLAG_DMAMAP
;
5053 * swap_buf_le16 - swap halves of 16-bit words in place
5054 * @buf: Buffer to swap
5055 * @buf_words: Number of 16-bit words in buffer.
5057 * Swap halves of 16-bit words if needed to convert from
5058 * little-endian byte order to native cpu byte order, or
5062 * Inherited from caller.
5064 void swap_buf_le16(u16
*buf
, unsigned int buf_words
)
5069 for (i
= 0; i
< buf_words
; i
++)
5070 buf
[i
] = le16_to_cpu(buf
[i
]);
5071 #endif /* __BIG_ENDIAN */
5075 * ata_data_xfer - Transfer data by PIO
5076 * @dev: device to target
5078 * @buflen: buffer length
5081 * Transfer data from/to the device data register by PIO.
5084 * Inherited from caller.
5089 unsigned int ata_data_xfer(struct ata_device
*dev
, unsigned char *buf
,
5090 unsigned int buflen
, int rw
)
5092 struct ata_port
*ap
= dev
->link
->ap
;
5093 void __iomem
*data_addr
= ap
->ioaddr
.data_addr
;
5094 unsigned int words
= buflen
>> 1;
5096 /* Transfer multiple of 2 bytes */
5098 ioread16_rep(data_addr
, buf
, words
);
5100 iowrite16_rep(data_addr
, buf
, words
);
5102 /* Transfer trailing 1 byte, if any. */
5103 if (unlikely(buflen
& 0x01)) {
5104 __le16 align_buf
[1] = { 0 };
5105 unsigned char *trailing_buf
= buf
+ buflen
- 1;
5108 align_buf
[0] = cpu_to_le16(ioread16(data_addr
));
5109 memcpy(trailing_buf
, align_buf
, 1);
5111 memcpy(align_buf
, trailing_buf
, 1);
5112 iowrite16(le16_to_cpu(align_buf
[0]), data_addr
);
5121 * ata_data_xfer_noirq - Transfer data by PIO
5122 * @dev: device to target
5124 * @buflen: buffer length
5127 * Transfer data from/to the device data register by PIO. Do the
5128 * transfer with interrupts disabled.
5131 * Inherited from caller.
5136 unsigned int ata_data_xfer_noirq(struct ata_device
*dev
, unsigned char *buf
,
5137 unsigned int buflen
, int rw
)
5139 unsigned long flags
;
5140 unsigned int consumed
;
5142 local_irq_save(flags
);
5143 consumed
= ata_data_xfer(dev
, buf
, buflen
, rw
);
5144 local_irq_restore(flags
);
5151 * ata_pio_sector - Transfer a sector of data.
5152 * @qc: Command on going
5154 * Transfer qc->sect_size bytes of data from/to the ATA device.
5157 * Inherited from caller.
5160 static void ata_pio_sector(struct ata_queued_cmd
*qc
)
5162 int do_write
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
);
5163 struct ata_port
*ap
= qc
->ap
;
5165 unsigned int offset
;
5168 if (qc
->curbytes
== qc
->nbytes
- qc
->sect_size
)
5169 ap
->hsm_task_state
= HSM_ST_LAST
;
5171 page
= sg_page(qc
->cursg
);
5172 offset
= qc
->cursg
->offset
+ qc
->cursg_ofs
;
5174 /* get the current page and offset */
5175 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
5176 offset
%= PAGE_SIZE
;
5178 DPRINTK("data %s\n", qc
->tf
.flags
& ATA_TFLAG_WRITE
? "write" : "read");
5180 if (PageHighMem(page
)) {
5181 unsigned long flags
;
5183 /* FIXME: use a bounce buffer */
5184 local_irq_save(flags
);
5185 buf
= kmap_atomic(page
, KM_IRQ0
);
5187 /* do the actual data transfer */
5188 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, qc
->sect_size
, do_write
);
5190 kunmap_atomic(buf
, KM_IRQ0
);
5191 local_irq_restore(flags
);
5193 buf
= page_address(page
);
5194 ap
->ops
->data_xfer(qc
->dev
, buf
+ offset
, qc
->sect_size
, do_write
);
5197 qc
->curbytes
+= qc
->sect_size
;
5198 qc
->cursg_ofs
+= qc
->sect_size
;
5200 if (qc
->cursg_ofs
== qc
->cursg
->length
) {
5201 qc
->cursg
= sg_next(qc
->cursg
);
5207 * ata_pio_sectors - Transfer one or many sectors.
5208 * @qc: Command on going
5210 * Transfer one or many sectors of data from/to the
5211 * ATA device for the DRQ request.
5214 * Inherited from caller.
5217 static void ata_pio_sectors(struct ata_queued_cmd
*qc
)
5219 if (is_multi_taskfile(&qc
->tf
)) {
5220 /* READ/WRITE MULTIPLE */
5223 WARN_ON(qc
->dev
->multi_count
== 0);
5225 nsect
= min((qc
->nbytes
- qc
->curbytes
) / qc
->sect_size
,
5226 qc
->dev
->multi_count
);
5232 ata_altstatus(qc
->ap
); /* flush */
5236 * atapi_send_cdb - Write CDB bytes to hardware
5237 * @ap: Port to which ATAPI device is attached.
5238 * @qc: Taskfile currently active
5240 * When device has indicated its readiness to accept
5241 * a CDB, this function is called. Send the CDB.
5247 static void atapi_send_cdb(struct ata_port
*ap
, struct ata_queued_cmd
*qc
)
5250 DPRINTK("send cdb\n");
5251 WARN_ON(qc
->dev
->cdb_len
< 12);
5253 ap
->ops
->data_xfer(qc
->dev
, qc
->cdb
, qc
->dev
->cdb_len
, 1);
5254 ata_altstatus(ap
); /* flush */
5256 switch (qc
->tf
.protocol
) {
5257 case ATAPI_PROT_PIO
:
5258 ap
->hsm_task_state
= HSM_ST
;
5260 case ATAPI_PROT_NODATA
:
5261 ap
->hsm_task_state
= HSM_ST_LAST
;
5263 case ATAPI_PROT_DMA
:
5264 ap
->hsm_task_state
= HSM_ST_LAST
;
5265 /* initiate bmdma */
5266 ap
->ops
->bmdma_start(qc
);
5272 * __atapi_pio_bytes - Transfer data from/to the ATAPI device.
5273 * @qc: Command on going
5274 * @bytes: number of bytes
5276 * Transfer Transfer data from/to the ATAPI device.
5279 * Inherited from caller.
5282 static int __atapi_pio_bytes(struct ata_queued_cmd
*qc
, unsigned int bytes
)
5284 int rw
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
) ? WRITE
: READ
;
5285 struct ata_port
*ap
= qc
->ap
;
5286 struct ata_device
*dev
= qc
->dev
;
5287 struct ata_eh_info
*ehi
= &dev
->link
->eh_info
;
5288 struct scatterlist
*sg
;
5291 unsigned int offset
, count
, consumed
;
5295 if (unlikely(!sg
)) {
5296 ata_ehi_push_desc(ehi
, "unexpected or too much trailing data "
5297 "buf=%u cur=%u bytes=%u",
5298 qc
->nbytes
, qc
->curbytes
, bytes
);
5303 offset
= sg
->offset
+ qc
->cursg_ofs
;
5305 /* get the current page and offset */
5306 page
= nth_page(page
, (offset
>> PAGE_SHIFT
));
5307 offset
%= PAGE_SIZE
;
5309 /* don't overrun current sg */
5310 count
= min(sg
->length
- qc
->cursg_ofs
, bytes
);
5312 /* don't cross page boundaries */
5313 count
= min(count
, (unsigned int)PAGE_SIZE
- offset
);
5315 DPRINTK("data %s\n", qc
->tf
.flags
& ATA_TFLAG_WRITE
? "write" : "read");
5317 if (PageHighMem(page
)) {
5318 unsigned long flags
;
5320 /* FIXME: use bounce buffer */
5321 local_irq_save(flags
);
5322 buf
= kmap_atomic(page
, KM_IRQ0
);
5324 /* do the actual data transfer */
5325 consumed
= ap
->ops
->data_xfer(dev
, buf
+ offset
, count
, rw
);
5327 kunmap_atomic(buf
, KM_IRQ0
);
5328 local_irq_restore(flags
);
5330 buf
= page_address(page
);
5331 consumed
= ap
->ops
->data_xfer(dev
, buf
+ offset
, count
, rw
);
5334 bytes
-= min(bytes
, consumed
);
5335 qc
->curbytes
+= count
;
5336 qc
->cursg_ofs
+= count
;
5338 if (qc
->cursg_ofs
== sg
->length
) {
5339 qc
->cursg
= sg_next(qc
->cursg
);
5343 /* consumed can be larger than count only for the last transfer */
5344 WARN_ON(qc
->cursg
&& count
!= consumed
);
5352 * atapi_pio_bytes - Transfer data from/to the ATAPI device.
5353 * @qc: Command on going
5355 * Transfer Transfer data from/to the ATAPI device.
5358 * Inherited from caller.
5361 static void atapi_pio_bytes(struct ata_queued_cmd
*qc
)
5363 struct ata_port
*ap
= qc
->ap
;
5364 struct ata_device
*dev
= qc
->dev
;
5365 struct ata_eh_info
*ehi
= &dev
->link
->eh_info
;
5366 unsigned int ireason
, bc_lo
, bc_hi
, bytes
;
5367 int i_write
, do_write
= (qc
->tf
.flags
& ATA_TFLAG_WRITE
) ? 1 : 0;
5369 /* Abuse qc->result_tf for temp storage of intermediate TF
5370 * here to save some kernel stack usage.
5371 * For normal completion, qc->result_tf is not relevant. For
5372 * error, qc->result_tf is later overwritten by ata_qc_complete().
5373 * So, the correctness of qc->result_tf is not affected.
5375 ap
->ops
->tf_read(ap
, &qc
->result_tf
);
5376 ireason
= qc
->result_tf
.nsect
;
5377 bc_lo
= qc
->result_tf
.lbam
;
5378 bc_hi
= qc
->result_tf
.lbah
;
5379 bytes
= (bc_hi
<< 8) | bc_lo
;
5381 /* shall be cleared to zero, indicating xfer of data */
5382 if (unlikely(ireason
& (1 << 0)))
5385 /* make sure transfer direction matches expected */
5386 i_write
= ((ireason
& (1 << 1)) == 0) ? 1 : 0;
5387 if (unlikely(do_write
!= i_write
))
5390 if (unlikely(!bytes
))
5393 VPRINTK("ata%u: xfering %d bytes\n", ap
->print_id
, bytes
);
5395 if (unlikely(__atapi_pio_bytes(qc
, bytes
)))
5397 ata_altstatus(ap
); /* flush */
5402 ata_ehi_push_desc(ehi
, "ATAPI check failed (ireason=0x%x bytes=%u)",
5405 qc
->err_mask
|= AC_ERR_HSM
;
5406 ap
->hsm_task_state
= HSM_ST_ERR
;
5410 * ata_hsm_ok_in_wq - Check if the qc can be handled in the workqueue.
5411 * @ap: the target ata_port
5415 * 1 if ok in workqueue, 0 otherwise.
5418 static inline int ata_hsm_ok_in_wq(struct ata_port
*ap
, struct ata_queued_cmd
*qc
)
5420 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
5423 if (ap
->hsm_task_state
== HSM_ST_FIRST
) {
5424 if (qc
->tf
.protocol
== ATA_PROT_PIO
&&
5425 (qc
->tf
.flags
& ATA_TFLAG_WRITE
))
5428 if (ata_is_atapi(qc
->tf
.protocol
) &&
5429 !(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
5437 * ata_hsm_qc_complete - finish a qc running on standard HSM
5438 * @qc: Command to complete
5439 * @in_wq: 1 if called from workqueue, 0 otherwise
5441 * Finish @qc which is running on standard HSM.
5444 * If @in_wq is zero, spin_lock_irqsave(host lock).
5445 * Otherwise, none on entry and grabs host lock.
5447 static void ata_hsm_qc_complete(struct ata_queued_cmd
*qc
, int in_wq
)
5449 struct ata_port
*ap
= qc
->ap
;
5450 unsigned long flags
;
5452 if (ap
->ops
->error_handler
) {
5454 spin_lock_irqsave(ap
->lock
, flags
);
5456 /* EH might have kicked in while host lock is
5459 qc
= ata_qc_from_tag(ap
, qc
->tag
);
5461 if (likely(!(qc
->err_mask
& AC_ERR_HSM
))) {
5462 ap
->ops
->irq_on(ap
);
5463 ata_qc_complete(qc
);
5465 ata_port_freeze(ap
);
5468 spin_unlock_irqrestore(ap
->lock
, flags
);
5470 if (likely(!(qc
->err_mask
& AC_ERR_HSM
)))
5471 ata_qc_complete(qc
);
5473 ata_port_freeze(ap
);
5477 spin_lock_irqsave(ap
->lock
, flags
);
5478 ap
->ops
->irq_on(ap
);
5479 ata_qc_complete(qc
);
5480 spin_unlock_irqrestore(ap
->lock
, flags
);
5482 ata_qc_complete(qc
);
5487 * ata_hsm_move - move the HSM to the next state.
5488 * @ap: the target ata_port
5490 * @status: current device status
5491 * @in_wq: 1 if called from workqueue, 0 otherwise
5494 * 1 when poll next status needed, 0 otherwise.
5496 int ata_hsm_move(struct ata_port
*ap
, struct ata_queued_cmd
*qc
,
5497 u8 status
, int in_wq
)
5499 unsigned long flags
= 0;
5502 WARN_ON((qc
->flags
& ATA_QCFLAG_ACTIVE
) == 0);
5504 /* Make sure ata_qc_issue_prot() does not throw things
5505 * like DMA polling into the workqueue. Notice that
5506 * in_wq is not equivalent to (qc->tf.flags & ATA_TFLAG_POLLING).
5508 WARN_ON(in_wq
!= ata_hsm_ok_in_wq(ap
, qc
));
5511 DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
5512 ap
->print_id
, qc
->tf
.protocol
, ap
->hsm_task_state
, status
);
5514 switch (ap
->hsm_task_state
) {
5516 /* Send first data block or PACKET CDB */
5518 /* If polling, we will stay in the work queue after
5519 * sending the data. Otherwise, interrupt handler
5520 * takes over after sending the data.
5522 poll_next
= (qc
->tf
.flags
& ATA_TFLAG_POLLING
);
5524 /* check device status */
5525 if (unlikely((status
& ATA_DRQ
) == 0)) {
5526 /* handle BSY=0, DRQ=0 as error */
5527 if (likely(status
& (ATA_ERR
| ATA_DF
)))
5528 /* device stops HSM for abort/error */
5529 qc
->err_mask
|= AC_ERR_DEV
;
5531 /* HSM violation. Let EH handle this */
5532 qc
->err_mask
|= AC_ERR_HSM
;
5534 ap
->hsm_task_state
= HSM_ST_ERR
;
5538 /* Device should not ask for data transfer (DRQ=1)
5539 * when it finds something wrong.
5540 * We ignore DRQ here and stop the HSM by
5541 * changing hsm_task_state to HSM_ST_ERR and
5542 * let the EH abort the command or reset the device.
5544 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
5545 /* Some ATAPI tape drives forget to clear the ERR bit
5546 * when doing the next command (mostly request sense).
5547 * We ignore ERR here to workaround and proceed sending
5550 if (!(qc
->dev
->horkage
& ATA_HORKAGE_STUCK_ERR
)) {
5551 ata_port_printk(ap
, KERN_WARNING
,
5552 "DRQ=1 with device error, "
5553 "dev_stat 0x%X\n", status
);
5554 qc
->err_mask
|= AC_ERR_HSM
;
5555 ap
->hsm_task_state
= HSM_ST_ERR
;
5560 /* Send the CDB (atapi) or the first data block (ata pio out).
5561 * During the state transition, interrupt handler shouldn't
5562 * be invoked before the data transfer is complete and
5563 * hsm_task_state is changed. Hence, the following locking.
5566 spin_lock_irqsave(ap
->lock
, flags
);
5568 if (qc
->tf
.protocol
== ATA_PROT_PIO
) {
5569 /* PIO data out protocol.
5570 * send first data block.
5573 /* ata_pio_sectors() might change the state
5574 * to HSM_ST_LAST. so, the state is changed here
5575 * before ata_pio_sectors().
5577 ap
->hsm_task_state
= HSM_ST
;
5578 ata_pio_sectors(qc
);
5581 atapi_send_cdb(ap
, qc
);
5584 spin_unlock_irqrestore(ap
->lock
, flags
);
5586 /* if polling, ata_pio_task() handles the rest.
5587 * otherwise, interrupt handler takes over from here.
5592 /* complete command or read/write the data register */
5593 if (qc
->tf
.protocol
== ATAPI_PROT_PIO
) {
5594 /* ATAPI PIO protocol */
5595 if ((status
& ATA_DRQ
) == 0) {
5596 /* No more data to transfer or device error.
5597 * Device error will be tagged in HSM_ST_LAST.
5599 ap
->hsm_task_state
= HSM_ST_LAST
;
5603 /* Device should not ask for data transfer (DRQ=1)
5604 * when it finds something wrong.
5605 * We ignore DRQ here and stop the HSM by
5606 * changing hsm_task_state to HSM_ST_ERR and
5607 * let the EH abort the command or reset the device.
5609 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
5610 ata_port_printk(ap
, KERN_WARNING
, "DRQ=1 with "
5611 "device error, dev_stat 0x%X\n",
5613 qc
->err_mask
|= AC_ERR_HSM
;
5614 ap
->hsm_task_state
= HSM_ST_ERR
;
5618 atapi_pio_bytes(qc
);
5620 if (unlikely(ap
->hsm_task_state
== HSM_ST_ERR
))
5621 /* bad ireason reported by device */
5625 /* ATA PIO protocol */
5626 if (unlikely((status
& ATA_DRQ
) == 0)) {
5627 /* handle BSY=0, DRQ=0 as error */
5628 if (likely(status
& (ATA_ERR
| ATA_DF
)))
5629 /* device stops HSM for abort/error */
5630 qc
->err_mask
|= AC_ERR_DEV
;
5632 /* HSM violation. Let EH handle this.
5633 * Phantom devices also trigger this
5634 * condition. Mark hint.
5636 qc
->err_mask
|= AC_ERR_HSM
|
5639 ap
->hsm_task_state
= HSM_ST_ERR
;
5643 /* For PIO reads, some devices may ask for
5644 * data transfer (DRQ=1) alone with ERR=1.
5645 * We respect DRQ here and transfer one
5646 * block of junk data before changing the
5647 * hsm_task_state to HSM_ST_ERR.
5649 * For PIO writes, ERR=1 DRQ=1 doesn't make
5650 * sense since the data block has been
5651 * transferred to the device.
5653 if (unlikely(status
& (ATA_ERR
| ATA_DF
))) {
5654 /* data might be corrputed */
5655 qc
->err_mask
|= AC_ERR_DEV
;
5657 if (!(qc
->tf
.flags
& ATA_TFLAG_WRITE
)) {
5658 ata_pio_sectors(qc
);
5659 status
= ata_wait_idle(ap
);
5662 if (status
& (ATA_BUSY
| ATA_DRQ
))
5663 qc
->err_mask
|= AC_ERR_HSM
;
5665 /* ata_pio_sectors() might change the
5666 * state to HSM_ST_LAST. so, the state
5667 * is changed after ata_pio_sectors().
5669 ap
->hsm_task_state
= HSM_ST_ERR
;
5673 ata_pio_sectors(qc
);
5675 if (ap
->hsm_task_state
== HSM_ST_LAST
&&
5676 (!(qc
->tf
.flags
& ATA_TFLAG_WRITE
))) {
5678 status
= ata_wait_idle(ap
);
5687 if (unlikely(!ata_ok(status
))) {
5688 qc
->err_mask
|= __ac_err_mask(status
);
5689 ap
->hsm_task_state
= HSM_ST_ERR
;
5693 /* no more data to transfer */
5694 DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n",
5695 ap
->print_id
, qc
->dev
->devno
, status
);
5697 WARN_ON(qc
->err_mask
);
5699 ap
->hsm_task_state
= HSM_ST_IDLE
;
5701 /* complete taskfile transaction */
5702 ata_hsm_qc_complete(qc
, in_wq
);
5708 /* make sure qc->err_mask is available to
5709 * know what's wrong and recover
5711 WARN_ON(qc
->err_mask
== 0);
5713 ap
->hsm_task_state
= HSM_ST_IDLE
;
5715 /* complete taskfile transaction */
5716 ata_hsm_qc_complete(qc
, in_wq
);
5728 static void ata_pio_task(struct work_struct
*work
)
5730 struct ata_port
*ap
=
5731 container_of(work
, struct ata_port
, port_task
.work
);
5732 struct ata_queued_cmd
*qc
= ap
->port_task_data
;
5737 WARN_ON(ap
->hsm_task_state
== HSM_ST_IDLE
);
5740 * This is purely heuristic. This is a fast path.
5741 * Sometimes when we enter, BSY will be cleared in
5742 * a chk-status or two. If not, the drive is probably seeking
5743 * or something. Snooze for a couple msecs, then
5744 * chk-status again. If still busy, queue delayed work.
5746 status
= ata_busy_wait(ap
, ATA_BUSY
, 5);
5747 if (status
& ATA_BUSY
) {
5749 status
= ata_busy_wait(ap
, ATA_BUSY
, 10);
5750 if (status
& ATA_BUSY
) {
5751 ata_pio_queue_task(ap
, qc
, ATA_SHORT_PAUSE
);
5757 poll_next
= ata_hsm_move(ap
, qc
, status
, 1);
5759 /* another command or interrupt handler
5760 * may be running at this point.
5767 * ata_qc_new - Request an available ATA command, for queueing
5768 * @ap: Port associated with device @dev
5769 * @dev: Device from whom we request an available command structure
5775 static struct ata_queued_cmd
*ata_qc_new(struct ata_port
*ap
)
5777 struct ata_queued_cmd
*qc
= NULL
;
5780 /* no command while frozen */
5781 if (unlikely(ap
->pflags
& ATA_PFLAG_FROZEN
))
5784 /* the last tag is reserved for internal command. */
5785 for (i
= 0; i
< ATA_MAX_QUEUE
- 1; i
++)
5786 if (!test_and_set_bit(i
, &ap
->qc_allocated
)) {
5787 qc
= __ata_qc_from_tag(ap
, i
);
5798 * ata_qc_new_init - Request an available ATA command, and initialize it
5799 * @dev: Device from whom we request an available command structure
5805 struct ata_queued_cmd
*ata_qc_new_init(struct ata_device
*dev
)
5807 struct ata_port
*ap
= dev
->link
->ap
;
5808 struct ata_queued_cmd
*qc
;
5810 qc
= ata_qc_new(ap
);
5823 * ata_qc_free - free unused ata_queued_cmd
5824 * @qc: Command to complete
5826 * Designed to free unused ata_queued_cmd object
5827 * in case something prevents using it.
5830 * spin_lock_irqsave(host lock)
5832 void ata_qc_free(struct ata_queued_cmd
*qc
)
5834 struct ata_port
*ap
= qc
->ap
;
5837 WARN_ON(qc
== NULL
); /* ata_qc_from_tag _might_ return NULL */
5841 if (likely(ata_tag_valid(tag
))) {
5842 qc
->tag
= ATA_TAG_POISON
;
5843 clear_bit(tag
, &ap
->qc_allocated
);
5847 void __ata_qc_complete(struct ata_queued_cmd
*qc
)
5849 struct ata_port
*ap
= qc
->ap
;
5850 struct ata_link
*link
= qc
->dev
->link
;
5852 WARN_ON(qc
== NULL
); /* ata_qc_from_tag _might_ return NULL */
5853 WARN_ON(!(qc
->flags
& ATA_QCFLAG_ACTIVE
));
5855 if (likely(qc
->flags
& ATA_QCFLAG_DMAMAP
))
5858 /* command should be marked inactive atomically with qc completion */
5859 if (qc
->tf
.protocol
== ATA_PROT_NCQ
) {
5860 link
->sactive
&= ~(1 << qc
->tag
);
5862 ap
->nr_active_links
--;
5864 link
->active_tag
= ATA_TAG_POISON
;
5865 ap
->nr_active_links
--;
5868 /* clear exclusive status */
5869 if (unlikely(qc
->flags
& ATA_QCFLAG_CLEAR_EXCL
&&
5870 ap
->excl_link
== link
))
5871 ap
->excl_link
= NULL
;
5873 /* atapi: mark qc as inactive to prevent the interrupt handler
5874 * from completing the command twice later, before the error handler
5875 * is called. (when rc != 0 and atapi request sense is needed)
5877 qc
->flags
&= ~ATA_QCFLAG_ACTIVE
;
5878 ap
->qc_active
&= ~(1 << qc
->tag
);
5880 /* call completion callback */
5881 qc
->complete_fn(qc
);
5884 static void fill_result_tf(struct ata_queued_cmd
*qc
)
5886 struct ata_port
*ap
= qc
->ap
;
5888 qc
->result_tf
.flags
= qc
->tf
.flags
;
5889 ap
->ops
->tf_read(ap
, &qc
->result_tf
);
5892 static void ata_verify_xfer(struct ata_queued_cmd
*qc
)
5894 struct ata_device
*dev
= qc
->dev
;
5896 if (ata_tag_internal(qc
->tag
))
5899 if (ata_is_nodata(qc
->tf
.protocol
))
5902 if ((dev
->mwdma_mask
|| dev
->udma_mask
) && ata_is_pio(qc
->tf
.protocol
))
5905 dev
->flags
&= ~ATA_DFLAG_DUBIOUS_XFER
;
5909 * ata_qc_complete - Complete an active ATA command
5910 * @qc: Command to complete
5911 * @err_mask: ATA Status register contents
5913 * Indicate to the mid and upper layers that an ATA
5914 * command has completed, with either an ok or not-ok status.
5917 * spin_lock_irqsave(host lock)
5919 void ata_qc_complete(struct ata_queued_cmd
*qc
)
5921 struct ata_port
*ap
= qc
->ap
;
5923 /* XXX: New EH and old EH use different mechanisms to
5924 * synchronize EH with regular execution path.
5926 * In new EH, a failed qc is marked with ATA_QCFLAG_FAILED.
5927 * Normal execution path is responsible for not accessing a
5928 * failed qc. libata core enforces the rule by returning NULL
5929 * from ata_qc_from_tag() for failed qcs.
5931 * Old EH depends on ata_qc_complete() nullifying completion
5932 * requests if ATA_QCFLAG_EH_SCHEDULED is set. Old EH does
5933 * not synchronize with interrupt handler. Only PIO task is
5936 if (ap
->ops
->error_handler
) {
5937 struct ata_device
*dev
= qc
->dev
;
5938 struct ata_eh_info
*ehi
= &dev
->link
->eh_info
;
5940 WARN_ON(ap
->pflags
& ATA_PFLAG_FROZEN
);
5942 if (unlikely(qc
->err_mask
))
5943 qc
->flags
|= ATA_QCFLAG_FAILED
;
5945 if (unlikely(qc
->flags
& ATA_QCFLAG_FAILED
)) {
5946 if (!ata_tag_internal(qc
->tag
)) {
5947 /* always fill result TF for failed qc */
5949 ata_qc_schedule_eh(qc
);
5954 /* read result TF if requested */
5955 if (qc
->flags
& ATA_QCFLAG_RESULT_TF
)
5958 /* Some commands need post-processing after successful
5961 switch (qc
->tf
.command
) {
5962 case ATA_CMD_SET_FEATURES
:
5963 if (qc
->tf
.feature
!= SETFEATURES_WC_ON
&&
5964 qc
->tf
.feature
!= SETFEATURES_WC_OFF
)
5967 case ATA_CMD_INIT_DEV_PARAMS
: /* CHS translation changed */
5968 case ATA_CMD_SET_MULTI
: /* multi_count changed */
5969 /* revalidate device */
5970 ehi
->dev_action
[dev
->devno
] |= ATA_EH_REVALIDATE
;
5971 ata_port_schedule_eh(ap
);
5975 dev
->flags
|= ATA_DFLAG_SLEEPING
;
5979 if (unlikely(dev
->flags
& ATA_DFLAG_DUBIOUS_XFER
))
5980 ata_verify_xfer(qc
);
5982 __ata_qc_complete(qc
);
5984 if (qc
->flags
& ATA_QCFLAG_EH_SCHEDULED
)
5987 /* read result TF if failed or requested */
5988 if (qc
->err_mask
|| qc
->flags
& ATA_QCFLAG_RESULT_TF
)
5991 __ata_qc_complete(qc
);
5996 * ata_qc_complete_multiple - Complete multiple qcs successfully
5997 * @ap: port in question
5998 * @qc_active: new qc_active mask
5999 * @finish_qc: LLDD callback invoked before completing a qc
6001 * Complete in-flight commands. This functions is meant to be
6002 * called from low-level driver's interrupt routine to complete
6003 * requests normally. ap->qc_active and @qc_active is compared
6004 * and commands are completed accordingly.
6007 * spin_lock_irqsave(host lock)
6010 * Number of completed commands on success, -errno otherwise.
6012 int ata_qc_complete_multiple(struct ata_port
*ap
, u32 qc_active
,
6013 void (*finish_qc
)(struct ata_queued_cmd
*))
6019 done_mask
= ap
->qc_active
^ qc_active
;
6021 if (unlikely(done_mask
& qc_active
)) {
6022 ata_port_printk(ap
, KERN_ERR
, "illegal qc_active transition "
6023 "(%08x->%08x)\n", ap
->qc_active
, qc_active
);
6027 for (i
= 0; i
< ATA_MAX_QUEUE
; i
++) {
6028 struct ata_queued_cmd
*qc
;
6030 if (!(done_mask
& (1 << i
)))
6033 if ((qc
= ata_qc_from_tag(ap
, i
))) {
6036 ata_qc_complete(qc
);
6045 * ata_qc_issue - issue taskfile to device
6046 * @qc: command to issue to device
6048 * Prepare an ATA command to submission to device.
6049 * This includes mapping the data into a DMA-able
6050 * area, filling in the S/G table, and finally
6051 * writing the taskfile to hardware, starting the command.
6054 * spin_lock_irqsave(host lock)
6056 void ata_qc_issue(struct ata_queued_cmd
*qc
)
6058 struct ata_port
*ap
= qc
->ap
;
6059 struct ata_link
*link
= qc
->dev
->link
;
6060 u8 prot
= qc
->tf
.protocol
;
6062 /* Make sure only one non-NCQ command is outstanding. The
6063 * check is skipped for old EH because it reuses active qc to
6064 * request ATAPI sense.
6066 WARN_ON(ap
->ops
->error_handler
&& ata_tag_valid(link
->active_tag
));
6068 if (ata_is_ncq(prot
)) {
6069 WARN_ON(link
->sactive
& (1 << qc
->tag
));
6072 ap
->nr_active_links
++;
6073 link
->sactive
|= 1 << qc
->tag
;
6075 WARN_ON(link
->sactive
);
6077 ap
->nr_active_links
++;
6078 link
->active_tag
= qc
->tag
;
6081 qc
->flags
|= ATA_QCFLAG_ACTIVE
;
6082 ap
->qc_active
|= 1 << qc
->tag
;
6084 /* We guarantee to LLDs that they will have at least one
6085 * non-zero sg if the command is a data command.
6087 BUG_ON(ata_is_data(prot
) && (!qc
->sg
|| !qc
->n_elem
|| !qc
->nbytes
));
6089 if (ata_is_dma(prot
) || (ata_is_pio(prot
) &&
6090 (ap
->flags
& ATA_FLAG_PIO_DMA
)))
6091 if (ata_sg_setup(qc
))
6094 /* if device is sleeping, schedule reset and abort the link */
6095 if (unlikely(qc
->dev
->flags
& ATA_DFLAG_SLEEPING
)) {
6096 link
->eh_info
.action
|= ATA_EH_RESET
;
6097 ata_ehi_push_desc(&link
->eh_info
, "waking up from sleep");
6098 ata_link_abort(link
);
6102 ap
->ops
->qc_prep(qc
);
6104 qc
->err_mask
|= ap
->ops
->qc_issue(qc
);
6105 if (unlikely(qc
->err_mask
))
6110 qc
->err_mask
|= AC_ERR_SYSTEM
;
6112 ata_qc_complete(qc
);
6116 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner
6117 * @qc: command to issue to device
6119 * Using various libata functions and hooks, this function
6120 * starts an ATA command. ATA commands are grouped into
6121 * classes called "protocols", and issuing each type of protocol
6122 * is slightly different.
6124 * May be used as the qc_issue() entry in ata_port_operations.
6127 * spin_lock_irqsave(host lock)
6130 * Zero on success, AC_ERR_* mask on failure
6133 unsigned int ata_qc_issue_prot(struct ata_queued_cmd
*qc
)
6135 struct ata_port
*ap
= qc
->ap
;
6137 /* Use polling pio if the LLD doesn't handle
6138 * interrupt driven pio and atapi CDB interrupt.
6140 if (ap
->flags
& ATA_FLAG_PIO_POLLING
) {
6141 switch (qc
->tf
.protocol
) {
6143 case ATA_PROT_NODATA
:
6144 case ATAPI_PROT_PIO
:
6145 case ATAPI_PROT_NODATA
:
6146 qc
->tf
.flags
|= ATA_TFLAG_POLLING
;
6148 case ATAPI_PROT_DMA
:
6149 if (qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
)
6150 /* see ata_dma_blacklisted() */
6158 /* select the device */
6159 ata_dev_select(ap
, qc
->dev
->devno
, 1, 0);
6161 /* start the command */
6162 switch (qc
->tf
.protocol
) {
6163 case ATA_PROT_NODATA
:
6164 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
6165 ata_qc_set_polling(qc
);
6167 ata_tf_to_host(ap
, &qc
->tf
);
6168 ap
->hsm_task_state
= HSM_ST_LAST
;
6170 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
6171 ata_pio_queue_task(ap
, qc
, 0);
6176 WARN_ON(qc
->tf
.flags
& ATA_TFLAG_POLLING
);
6178 ap
->ops
->tf_load(ap
, &qc
->tf
); /* load tf registers */
6179 ap
->ops
->bmdma_setup(qc
); /* set up bmdma */
6180 ap
->ops
->bmdma_start(qc
); /* initiate bmdma */
6181 ap
->hsm_task_state
= HSM_ST_LAST
;
6185 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
6186 ata_qc_set_polling(qc
);
6188 ata_tf_to_host(ap
, &qc
->tf
);
6190 if (qc
->tf
.flags
& ATA_TFLAG_WRITE
) {
6191 /* PIO data out protocol */
6192 ap
->hsm_task_state
= HSM_ST_FIRST
;
6193 ata_pio_queue_task(ap
, qc
, 0);
6195 /* always send first data block using
6196 * the ata_pio_task() codepath.
6199 /* PIO data in protocol */
6200 ap
->hsm_task_state
= HSM_ST
;
6202 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
6203 ata_pio_queue_task(ap
, qc
, 0);
6205 /* if polling, ata_pio_task() handles the rest.
6206 * otherwise, interrupt handler takes over from here.
6212 case ATAPI_PROT_PIO
:
6213 case ATAPI_PROT_NODATA
:
6214 if (qc
->tf
.flags
& ATA_TFLAG_POLLING
)
6215 ata_qc_set_polling(qc
);
6217 ata_tf_to_host(ap
, &qc
->tf
);
6219 ap
->hsm_task_state
= HSM_ST_FIRST
;
6221 /* send cdb by polling if no cdb interrupt */
6222 if ((!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
)) ||
6223 (qc
->tf
.flags
& ATA_TFLAG_POLLING
))
6224 ata_pio_queue_task(ap
, qc
, 0);
6227 case ATAPI_PROT_DMA
:
6228 WARN_ON(qc
->tf
.flags
& ATA_TFLAG_POLLING
);
6230 ap
->ops
->tf_load(ap
, &qc
->tf
); /* load tf registers */
6231 ap
->ops
->bmdma_setup(qc
); /* set up bmdma */
6232 ap
->hsm_task_state
= HSM_ST_FIRST
;
6234 /* send cdb by polling if no cdb interrupt */
6235 if (!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
6236 ata_pio_queue_task(ap
, qc
, 0);
6241 return AC_ERR_SYSTEM
;
6248 * ata_host_intr - Handle host interrupt for given (port, task)
6249 * @ap: Port on which interrupt arrived (possibly...)
6250 * @qc: Taskfile currently active in engine
6252 * Handle host interrupt for given queued command. Currently,
6253 * only DMA interrupts are handled. All other commands are
6254 * handled via polling with interrupts disabled (nIEN bit).
6257 * spin_lock_irqsave(host lock)
6260 * One if interrupt was handled, zero if not (shared irq).
6263 inline unsigned int ata_host_intr(struct ata_port
*ap
,
6264 struct ata_queued_cmd
*qc
)
6266 struct ata_eh_info
*ehi
= &ap
->link
.eh_info
;
6267 u8 status
, host_stat
= 0;
6269 VPRINTK("ata%u: protocol %d task_state %d\n",
6270 ap
->print_id
, qc
->tf
.protocol
, ap
->hsm_task_state
);
6272 /* Check whether we are expecting interrupt in this state */
6273 switch (ap
->hsm_task_state
) {
6275 /* Some pre-ATAPI-4 devices assert INTRQ
6276 * at this state when ready to receive CDB.
6279 /* Check the ATA_DFLAG_CDB_INTR flag is enough here.
6280 * The flag was turned on only for atapi devices. No
6281 * need to check ata_is_atapi(qc->tf.protocol) again.
6283 if (!(qc
->dev
->flags
& ATA_DFLAG_CDB_INTR
))
6287 if (qc
->tf
.protocol
== ATA_PROT_DMA
||
6288 qc
->tf
.protocol
== ATAPI_PROT_DMA
) {
6289 /* check status of DMA engine */
6290 host_stat
= ap
->ops
->bmdma_status(ap
);
6291 VPRINTK("ata%u: host_stat 0x%X\n",
6292 ap
->print_id
, host_stat
);
6294 /* if it's not our irq... */
6295 if (!(host_stat
& ATA_DMA_INTR
))
6298 /* before we do anything else, clear DMA-Start bit */
6299 ap
->ops
->bmdma_stop(qc
);
6301 if (unlikely(host_stat
& ATA_DMA_ERR
)) {
6302 /* error when transfering data to/from memory */
6303 qc
->err_mask
|= AC_ERR_HOST_BUS
;
6304 ap
->hsm_task_state
= HSM_ST_ERR
;
6314 /* check altstatus */
6315 status
= ata_altstatus(ap
);
6316 if (status
& ATA_BUSY
)
6319 /* check main status, clearing INTRQ */
6320 status
= ata_chk_status(ap
);
6321 if (unlikely(status
& ATA_BUSY
))
6324 /* ack bmdma irq events */
6325 ap
->ops
->irq_clear(ap
);
6327 ata_hsm_move(ap
, qc
, status
, 0);
6329 if (unlikely(qc
->err_mask
) && (qc
->tf
.protocol
== ATA_PROT_DMA
||
6330 qc
->tf
.protocol
== ATAPI_PROT_DMA
))
6331 ata_ehi_push_desc(ehi
, "BMDMA stat 0x%x", host_stat
);
6333 return 1; /* irq handled */
6336 ap
->stats
.idle_irq
++;
6339 if ((ap
->stats
.idle_irq
% 1000) == 0) {
6341 ap
->ops
->irq_clear(ap
);
6342 ata_port_printk(ap
, KERN_WARNING
, "irq trap\n");
6346 return 0; /* irq not handled */
6350 * ata_interrupt - Default ATA host interrupt handler
6351 * @irq: irq line (unused)
6352 * @dev_instance: pointer to our ata_host information structure
6354 * Default interrupt handler for PCI IDE devices. Calls
6355 * ata_host_intr() for each port that is not disabled.
6358 * Obtains host lock during operation.
6361 * IRQ_NONE or IRQ_HANDLED.
6364 irqreturn_t
ata_interrupt(int irq
, void *dev_instance
)
6366 struct ata_host
*host
= dev_instance
;
6368 unsigned int handled
= 0;
6369 unsigned long flags
;
6371 /* TODO: make _irqsave conditional on x86 PCI IDE legacy mode */
6372 spin_lock_irqsave(&host
->lock
, flags
);
6374 for (i
= 0; i
< host
->n_ports
; i
++) {
6375 struct ata_port
*ap
;
6377 ap
= host
->ports
[i
];
6379 !(ap
->flags
& ATA_FLAG_DISABLED
)) {
6380 struct ata_queued_cmd
*qc
;
6382 qc
= ata_qc_from_tag(ap
, ap
->link
.active_tag
);
6383 if (qc
&& (!(qc
->tf
.flags
& ATA_TFLAG_POLLING
)) &&
6384 (qc
->flags
& ATA_QCFLAG_ACTIVE
))
6385 handled
|= ata_host_intr(ap
, qc
);
6389 spin_unlock_irqrestore(&host
->lock
, flags
);
6391 return IRQ_RETVAL(handled
);
6395 * sata_scr_valid - test whether SCRs are accessible
6396 * @link: ATA link to test SCR accessibility for
6398 * Test whether SCRs are accessible for @link.
6404 * 1 if SCRs are accessible, 0 otherwise.
6406 int sata_scr_valid(struct ata_link
*link
)
6408 struct ata_port
*ap
= link
->ap
;
6410 return (ap
->flags
& ATA_FLAG_SATA
) && ap
->ops
->scr_read
;
6414 * sata_scr_read - read SCR register of the specified port
6415 * @link: ATA link to read SCR for
6417 * @val: Place to store read value
6419 * Read SCR register @reg of @link into *@val. This function is
6420 * guaranteed to succeed if @link is ap->link, the cable type of
6421 * the port is SATA and the port implements ->scr_read.
6424 * None if @link is ap->link. Kernel thread context otherwise.
6427 * 0 on success, negative errno on failure.
6429 int sata_scr_read(struct ata_link
*link
, int reg
, u32
*val
)
6431 if (ata_is_host_link(link
)) {
6432 struct ata_port
*ap
= link
->ap
;
6434 if (sata_scr_valid(link
))
6435 return ap
->ops
->scr_read(ap
, reg
, val
);
6439 return sata_pmp_scr_read(link
, reg
, val
);
6443 * sata_scr_write - write SCR register of the specified port
6444 * @link: ATA link to write SCR for
6445 * @reg: SCR to write
6446 * @val: value to write
6448 * Write @val to SCR register @reg of @link. This function is
6449 * guaranteed to succeed if @link is ap->link, the cable type of
6450 * the port is SATA and the port implements ->scr_read.
6453 * None if @link is ap->link. Kernel thread context otherwise.
6456 * 0 on success, negative errno on failure.
6458 int sata_scr_write(struct ata_link
*link
, int reg
, u32 val
)
6460 if (ata_is_host_link(link
)) {
6461 struct ata_port
*ap
= link
->ap
;
6463 if (sata_scr_valid(link
))
6464 return ap
->ops
->scr_write(ap
, reg
, val
);
6468 return sata_pmp_scr_write(link
, reg
, val
);
6472 * sata_scr_write_flush - write SCR register of the specified port and flush
6473 * @link: ATA link to write SCR for
6474 * @reg: SCR to write
6475 * @val: value to write
6477 * This function is identical to sata_scr_write() except that this
6478 * function performs flush after writing to the register.
6481 * None if @link is ap->link. Kernel thread context otherwise.
6484 * 0 on success, negative errno on failure.
6486 int sata_scr_write_flush(struct ata_link
*link
, int reg
, u32 val
)
6488 if (ata_is_host_link(link
)) {
6489 struct ata_port
*ap
= link
->ap
;
6492 if (sata_scr_valid(link
)) {
6493 rc
= ap
->ops
->scr_write(ap
, reg
, val
);
6495 rc
= ap
->ops
->scr_read(ap
, reg
, &val
);
6501 return sata_pmp_scr_write(link
, reg
, val
);
6505 * ata_link_online - test whether the given link is online
6506 * @link: ATA link to test
6508 * Test whether @link is online. Note that this function returns
6509 * 0 if online status of @link cannot be obtained, so
6510 * ata_link_online(link) != !ata_link_offline(link).
6516 * 1 if the port online status is available and online.
6518 int ata_link_online(struct ata_link
*link
)
6522 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
) == 0 &&
6523 (sstatus
& 0xf) == 0x3)
6529 * ata_link_offline - test whether the given link is offline
6530 * @link: ATA link to test
6532 * Test whether @link is offline. Note that this function
6533 * returns 0 if offline status of @link cannot be obtained, so
6534 * ata_link_online(link) != !ata_link_offline(link).
6540 * 1 if the port offline status is available and offline.
6542 int ata_link_offline(struct ata_link
*link
)
6546 if (sata_scr_read(link
, SCR_STATUS
, &sstatus
) == 0 &&
6547 (sstatus
& 0xf) != 0x3)
6552 int ata_flush_cache(struct ata_device
*dev
)
6554 unsigned int err_mask
;
6557 if (!ata_try_flush_cache(dev
))
6560 if (dev
->flags
& ATA_DFLAG_FLUSH_EXT
)
6561 cmd
= ATA_CMD_FLUSH_EXT
;
6563 cmd
= ATA_CMD_FLUSH
;
6565 /* This is wrong. On a failed flush we get back the LBA of the lost
6566 sector and we should (assuming it wasn't aborted as unknown) issue
6567 a further flush command to continue the writeback until it
6569 err_mask
= ata_do_simple_cmd(dev
, cmd
);
6571 ata_dev_printk(dev
, KERN_ERR
, "failed to flush cache\n");
6579 static int ata_host_request_pm(struct ata_host
*host
, pm_message_t mesg
,
6580 unsigned int action
, unsigned int ehi_flags
,
6583 unsigned long flags
;
6586 for (i
= 0; i
< host
->n_ports
; i
++) {
6587 struct ata_port
*ap
= host
->ports
[i
];
6588 struct ata_link
*link
;
6590 /* Previous resume operation might still be in
6591 * progress. Wait for PM_PENDING to clear.
6593 if (ap
->pflags
& ATA_PFLAG_PM_PENDING
) {
6594 ata_port_wait_eh(ap
);
6595 WARN_ON(ap
->pflags
& ATA_PFLAG_PM_PENDING
);
6598 /* request PM ops to EH */
6599 spin_lock_irqsave(ap
->lock
, flags
);
6604 ap
->pm_result
= &rc
;
6607 ap
->pflags
|= ATA_PFLAG_PM_PENDING
;
6608 __ata_port_for_each_link(link
, ap
) {
6609 link
->eh_info
.action
|= action
;
6610 link
->eh_info
.flags
|= ehi_flags
;
6613 ata_port_schedule_eh(ap
);
6615 spin_unlock_irqrestore(ap
->lock
, flags
);
6617 /* wait and check result */
6619 ata_port_wait_eh(ap
);
6620 WARN_ON(ap
->pflags
& ATA_PFLAG_PM_PENDING
);
6630 * ata_host_suspend - suspend host
6631 * @host: host to suspend
6634 * Suspend @host. Actual operation is performed by EH. This
6635 * function requests EH to perform PM operations and waits for EH
6639 * Kernel thread context (may sleep).
6642 * 0 on success, -errno on failure.
6644 int ata_host_suspend(struct ata_host
*host
, pm_message_t mesg
)
6649 * disable link pm on all ports before requesting
6652 ata_lpm_enable(host
);
6654 rc
= ata_host_request_pm(host
, mesg
, 0, ATA_EHI_QUIET
, 1);
6656 host
->dev
->power
.power_state
= mesg
;
6661 * ata_host_resume - resume host
6662 * @host: host to resume
6664 * Resume @host. Actual operation is performed by EH. This
6665 * function requests EH to perform PM operations and returns.
6666 * Note that all resume operations are performed parallely.
6669 * Kernel thread context (may sleep).
6671 void ata_host_resume(struct ata_host
*host
)
6673 ata_host_request_pm(host
, PMSG_ON
, ATA_EH_RESET
,
6674 ATA_EHI_NO_AUTOPSY
| ATA_EHI_QUIET
, 0);
6675 host
->dev
->power
.power_state
= PMSG_ON
;
6677 /* reenable link pm */
6678 ata_lpm_disable(host
);
6683 * ata_port_start - Set port up for dma.
6684 * @ap: Port to initialize
6686 * Called just after data structures for each port are
6687 * initialized. Allocates space for PRD table.
6689 * May be used as the port_start() entry in ata_port_operations.
6692 * Inherited from caller.
6694 int ata_port_start(struct ata_port
*ap
)
6696 struct device
*dev
= ap
->dev
;
6698 ap
->prd
= dmam_alloc_coherent(dev
, ATA_PRD_TBL_SZ
, &ap
->prd_dma
,
6707 * ata_dev_init - Initialize an ata_device structure
6708 * @dev: Device structure to initialize
6710 * Initialize @dev in preparation for probing.
6713 * Inherited from caller.
6715 void ata_dev_init(struct ata_device
*dev
)
6717 struct ata_link
*link
= dev
->link
;
6718 struct ata_port
*ap
= link
->ap
;
6719 unsigned long flags
;
6721 /* SATA spd limit is bound to the first device */
6722 link
->sata_spd_limit
= link
->hw_sata_spd_limit
;
6725 /* High bits of dev->flags are used to record warm plug
6726 * requests which occur asynchronously. Synchronize using
6729 spin_lock_irqsave(ap
->lock
, flags
);
6730 dev
->flags
&= ~ATA_DFLAG_INIT_MASK
;
6732 spin_unlock_irqrestore(ap
->lock
, flags
);
6734 memset((void *)dev
+ ATA_DEVICE_CLEAR_OFFSET
, 0,
6735 sizeof(*dev
) - ATA_DEVICE_CLEAR_OFFSET
);
6736 dev
->pio_mask
= UINT_MAX
;
6737 dev
->mwdma_mask
= UINT_MAX
;
6738 dev
->udma_mask
= UINT_MAX
;
6742 * ata_link_init - Initialize an ata_link structure
6743 * @ap: ATA port link is attached to
6744 * @link: Link structure to initialize
6745 * @pmp: Port multiplier port number
6750 * Kernel thread context (may sleep)
6752 void ata_link_init(struct ata_port
*ap
, struct ata_link
*link
, int pmp
)
6756 /* clear everything except for devices */
6757 memset(link
, 0, offsetof(struct ata_link
, device
[0]));
6761 link
->active_tag
= ATA_TAG_POISON
;
6762 link
->hw_sata_spd_limit
= UINT_MAX
;
6764 /* can't use iterator, ap isn't initialized yet */
6765 for (i
= 0; i
< ATA_MAX_DEVICES
; i
++) {
6766 struct ata_device
*dev
= &link
->device
[i
];
6769 dev
->devno
= dev
- link
->device
;
6775 * sata_link_init_spd - Initialize link->sata_spd_limit
6776 * @link: Link to configure sata_spd_limit for
6778 * Initialize @link->[hw_]sata_spd_limit to the currently
6782 * Kernel thread context (may sleep).
6785 * 0 on success, -errno on failure.
6787 int sata_link_init_spd(struct ata_link
*link
)
6793 rc
= sata_scr_read(link
, SCR_CONTROL
, &scontrol
);
6797 spd
= (scontrol
>> 4) & 0xf;
6799 link
->hw_sata_spd_limit
&= (1 << spd
) - 1;
6801 ata_force_spd_limit(link
);
6803 link
->sata_spd_limit
= link
->hw_sata_spd_limit
;
6809 * ata_port_alloc - allocate and initialize basic ATA port resources
6810 * @host: ATA host this allocated port belongs to
6812 * Allocate and initialize basic ATA port resources.
6815 * Allocate ATA port on success, NULL on failure.
6818 * Inherited from calling layer (may sleep).
6820 struct ata_port
*ata_port_alloc(struct ata_host
*host
)
6822 struct ata_port
*ap
;
6826 ap
= kzalloc(sizeof(*ap
), GFP_KERNEL
);
6830 ap
->pflags
|= ATA_PFLAG_INITIALIZING
;
6831 ap
->lock
= &host
->lock
;
6832 ap
->flags
= ATA_FLAG_DISABLED
;
6834 ap
->ctl
= ATA_DEVCTL_OBS
;
6836 ap
->dev
= host
->dev
;
6837 ap
->last_ctl
= 0xFF;
6839 #if defined(ATA_VERBOSE_DEBUG)
6840 /* turn on all debugging levels */
6841 ap
->msg_enable
= 0x00FF;
6842 #elif defined(ATA_DEBUG)
6843 ap
->msg_enable
= ATA_MSG_DRV
| ATA_MSG_INFO
| ATA_MSG_CTL
| ATA_MSG_WARN
| ATA_MSG_ERR
;
6845 ap
->msg_enable
= ATA_MSG_DRV
| ATA_MSG_ERR
| ATA_MSG_WARN
;
6848 INIT_DELAYED_WORK(&ap
->port_task
, ata_pio_task
);
6849 INIT_DELAYED_WORK(&ap
->hotplug_task
, ata_scsi_hotplug
);
6850 INIT_WORK(&ap
->scsi_rescan_task
, ata_scsi_dev_rescan
);
6851 INIT_LIST_HEAD(&ap
->eh_done_q
);
6852 init_waitqueue_head(&ap
->eh_wait_q
);
6853 init_timer_deferrable(&ap
->fastdrain_timer
);
6854 ap
->fastdrain_timer
.function
= ata_eh_fastdrain_timerfn
;
6855 ap
->fastdrain_timer
.data
= (unsigned long)ap
;
6857 ap
->cbl
= ATA_CBL_NONE
;
6859 ata_link_init(ap
, &ap
->link
, 0);
6862 ap
->stats
.unhandled_irq
= 1;
6863 ap
->stats
.idle_irq
= 1;
6868 static void ata_host_release(struct device
*gendev
, void *res
)
6870 struct ata_host
*host
= dev_get_drvdata(gendev
);
6873 for (i
= 0; i
< host
->n_ports
; i
++) {
6874 struct ata_port
*ap
= host
->ports
[i
];
6880 scsi_host_put(ap
->scsi_host
);
6882 kfree(ap
->pmp_link
);
6884 host
->ports
[i
] = NULL
;
6887 dev_set_drvdata(gendev
, NULL
);
6891 * ata_host_alloc - allocate and init basic ATA host resources
6892 * @dev: generic device this host is associated with
6893 * @max_ports: maximum number of ATA ports associated with this host
6895 * Allocate and initialize basic ATA host resources. LLD calls
6896 * this function to allocate a host, initializes it fully and
6897 * attaches it using ata_host_register().
6899 * @max_ports ports are allocated and host->n_ports is
6900 * initialized to @max_ports. The caller is allowed to decrease
6901 * host->n_ports before calling ata_host_register(). The unused
6902 * ports will be automatically freed on registration.
6905 * Allocate ATA host on success, NULL on failure.
6908 * Inherited from calling layer (may sleep).
6910 struct ata_host
*ata_host_alloc(struct device
*dev
, int max_ports
)
6912 struct ata_host
*host
;
6918 if (!devres_open_group(dev
, NULL
, GFP_KERNEL
))
6921 /* alloc a container for our list of ATA ports (buses) */
6922 sz
= sizeof(struct ata_host
) + (max_ports
+ 1) * sizeof(void *);
6923 /* alloc a container for our list of ATA ports (buses) */
6924 host
= devres_alloc(ata_host_release
, sz
, GFP_KERNEL
);
6928 devres_add(dev
, host
);
6929 dev_set_drvdata(dev
, host
);
6931 spin_lock_init(&host
->lock
);
6933 host
->n_ports
= max_ports
;
6935 /* allocate ports bound to this host */
6936 for (i
= 0; i
< max_ports
; i
++) {
6937 struct ata_port
*ap
;
6939 ap
= ata_port_alloc(host
);
6944 host
->ports
[i
] = ap
;
6947 devres_remove_group(dev
, NULL
);
6951 devres_release_group(dev
, NULL
);
6956 * ata_host_alloc_pinfo - alloc host and init with port_info array
6957 * @dev: generic device this host is associated with
6958 * @ppi: array of ATA port_info to initialize host with
6959 * @n_ports: number of ATA ports attached to this host
6961 * Allocate ATA host and initialize with info from @ppi. If NULL
6962 * terminated, @ppi may contain fewer entries than @n_ports. The
6963 * last entry will be used for the remaining ports.
6966 * Allocate ATA host on success, NULL on failure.
6969 * Inherited from calling layer (may sleep).
6971 struct ata_host
*ata_host_alloc_pinfo(struct device
*dev
,
6972 const struct ata_port_info
* const * ppi
,
6975 const struct ata_port_info
*pi
;
6976 struct ata_host
*host
;
6979 host
= ata_host_alloc(dev
, n_ports
);
6983 for (i
= 0, j
= 0, pi
= NULL
; i
< host
->n_ports
; i
++) {
6984 struct ata_port
*ap
= host
->ports
[i
];
6989 ap
->pio_mask
= pi
->pio_mask
;
6990 ap
->mwdma_mask
= pi
->mwdma_mask
;
6991 ap
->udma_mask
= pi
->udma_mask
;
6992 ap
->flags
|= pi
->flags
;
6993 ap
->link
.flags
|= pi
->link_flags
;
6994 ap
->ops
= pi
->port_ops
;
6996 if (!host
->ops
&& (pi
->port_ops
!= &ata_dummy_port_ops
))
6997 host
->ops
= pi
->port_ops
;
6998 if (!host
->private_data
&& pi
->private_data
)
6999 host
->private_data
= pi
->private_data
;
7005 static void ata_host_stop(struct device
*gendev
, void *res
)
7007 struct ata_host
*host
= dev_get_drvdata(gendev
);
7010 WARN_ON(!(host
->flags
& ATA_HOST_STARTED
));
7012 for (i
= 0; i
< host
->n_ports
; i
++) {
7013 struct ata_port
*ap
= host
->ports
[i
];
7015 if (ap
->ops
->port_stop
)
7016 ap
->ops
->port_stop(ap
);
7019 if (host
->ops
->host_stop
)
7020 host
->ops
->host_stop(host
);
7024 * ata_finalize_port_ops - finalize ata_port_operations
7025 * @ops: ata_port_operations to finalize
7027 * An ata_port_operations can inherit from another ops and that
7028 * ops can again inherit from another. This can go on as many
7029 * times as necessary as long as there is no loop in the
7030 * inheritance chain.
7032 * Ops tables are finalized when the host is started. NULL or
7033 * unspecified entries are inherited from the closet ancestor
7034 * which has the method and the entry is populated with it.
7035 * After finalization, the ops table directly points to all the
7036 * methods and ->inherits is no longer necessary and cleared.
7038 * Using ATA_OP_NULL, inheriting ops can force a method to NULL.
7043 static void ata_finalize_port_ops(struct ata_port_operations
*ops
)
7045 static spinlock_t lock
= SPIN_LOCK_UNLOCKED
;
7046 const struct ata_port_operations
*cur
;
7047 void **begin
= (void **)ops
;
7048 void **end
= (void **)&ops
->inherits
;
7051 if (!ops
|| !ops
->inherits
)
7056 for (cur
= ops
->inherits
; cur
; cur
= cur
->inherits
) {
7057 void **inherit
= (void **)cur
;
7059 for (pp
= begin
; pp
< end
; pp
++, inherit
++)
7064 for (pp
= begin
; pp
< end
; pp
++)
7068 ops
->inherits
= NULL
;
7074 * ata_host_start - start and freeze ports of an ATA host
7075 * @host: ATA host to start ports for
7077 * Start and then freeze ports of @host. Started status is
7078 * recorded in host->flags, so this function can be called
7079 * multiple times. Ports are guaranteed to get started only
7080 * once. If host->ops isn't initialized yet, its set to the
7081 * first non-dummy port ops.
7084 * Inherited from calling layer (may sleep).
7087 * 0 if all ports are started successfully, -errno otherwise.
7089 int ata_host_start(struct ata_host
*host
)
7092 void *start_dr
= NULL
;
7095 if (host
->flags
& ATA_HOST_STARTED
)
7098 ata_finalize_port_ops(host
->ops
);
7100 for (i
= 0; i
< host
->n_ports
; i
++) {
7101 struct ata_port
*ap
= host
->ports
[i
];
7103 ata_finalize_port_ops(ap
->ops
);
7105 if (!host
->ops
&& !ata_port_is_dummy(ap
))
7106 host
->ops
= ap
->ops
;
7108 if (ap
->ops
->port_stop
)
7112 if (host
->ops
->host_stop
)
7116 start_dr
= devres_alloc(ata_host_stop
, 0, GFP_KERNEL
);
7121 for (i
= 0; i
< host
->n_ports
; i
++) {
7122 struct ata_port
*ap
= host
->ports
[i
];
7124 if (ap
->ops
->port_start
) {
7125 rc
= ap
->ops
->port_start(ap
);
7128 dev_printk(KERN_ERR
, host
->dev
,
7129 "failed to start port %d "
7130 "(errno=%d)\n", i
, rc
);
7134 ata_eh_freeze_port(ap
);
7138 devres_add(host
->dev
, start_dr
);
7139 host
->flags
|= ATA_HOST_STARTED
;
7144 struct ata_port
*ap
= host
->ports
[i
];
7146 if (ap
->ops
->port_stop
)
7147 ap
->ops
->port_stop(ap
);
7149 devres_free(start_dr
);
7154 * ata_sas_host_init - Initialize a host struct
7155 * @host: host to initialize
7156 * @dev: device host is attached to
7157 * @flags: host flags
7161 * PCI/etc. bus probe sem.
7164 /* KILLME - the only user left is ipr */
7165 void ata_host_init(struct ata_host
*host
, struct device
*dev
,
7166 unsigned long flags
, struct ata_port_operations
*ops
)
7168 spin_lock_init(&host
->lock
);
7170 host
->flags
= flags
;
7175 * ata_host_register - register initialized ATA host
7176 * @host: ATA host to register
7177 * @sht: template for SCSI host
7179 * Register initialized ATA host. @host is allocated using
7180 * ata_host_alloc() and fully initialized by LLD. This function
7181 * starts ports, registers @host with ATA and SCSI layers and
7182 * probe registered devices.
7185 * Inherited from calling layer (may sleep).
7188 * 0 on success, -errno otherwise.
7190 int ata_host_register(struct ata_host
*host
, struct scsi_host_template
*sht
)
7194 /* host must have been started */
7195 if (!(host
->flags
& ATA_HOST_STARTED
)) {
7196 dev_printk(KERN_ERR
, host
->dev
,
7197 "BUG: trying to register unstarted host\n");
7202 /* Blow away unused ports. This happens when LLD can't
7203 * determine the exact number of ports to allocate at
7206 for (i
= host
->n_ports
; host
->ports
[i
]; i
++)
7207 kfree(host
->ports
[i
]);
7209 /* give ports names and add SCSI hosts */
7210 for (i
= 0; i
< host
->n_ports
; i
++)
7211 host
->ports
[i
]->print_id
= ata_print_id
++;
7213 rc
= ata_scsi_add_hosts(host
, sht
);
7217 /* associate with ACPI nodes */
7218 ata_acpi_associate(host
);
7220 /* set cable, sata_spd_limit and report */
7221 for (i
= 0; i
< host
->n_ports
; i
++) {
7222 struct ata_port
*ap
= host
->ports
[i
];
7223 unsigned long xfer_mask
;
7225 /* set SATA cable type if still unset */
7226 if (ap
->cbl
== ATA_CBL_NONE
&& (ap
->flags
& ATA_FLAG_SATA
))
7227 ap
->cbl
= ATA_CBL_SATA
;
7229 /* init sata_spd_limit to the current value */
7230 sata_link_init_spd(&ap
->link
);
7232 /* print per-port info to dmesg */
7233 xfer_mask
= ata_pack_xfermask(ap
->pio_mask
, ap
->mwdma_mask
,
7236 if (!ata_port_is_dummy(ap
)) {
7237 ata_port_printk(ap
, KERN_INFO
,
7238 "%cATA max %s %s\n",
7239 (ap
->flags
& ATA_FLAG_SATA
) ? 'S' : 'P',
7240 ata_mode_string(xfer_mask
),
7241 ap
->link
.eh_info
.desc
);
7242 ata_ehi_clear_desc(&ap
->link
.eh_info
);
7244 ata_port_printk(ap
, KERN_INFO
, "DUMMY\n");
7247 /* perform each probe synchronously */
7248 DPRINTK("probe begin\n");
7249 for (i
= 0; i
< host
->n_ports
; i
++) {
7250 struct ata_port
*ap
= host
->ports
[i
];
7253 if (ap
->ops
->error_handler
) {
7254 struct ata_eh_info
*ehi
= &ap
->link
.eh_info
;
7255 unsigned long flags
;
7259 /* kick EH for boot probing */
7260 spin_lock_irqsave(ap
->lock
, flags
);
7262 ehi
->probe_mask
|= ATA_ALL_DEVICES
;
7263 ehi
->action
|= ATA_EH_RESET
;
7264 ehi
->flags
|= ATA_EHI_NO_AUTOPSY
| ATA_EHI_QUIET
;
7266 ap
->pflags
&= ~ATA_PFLAG_INITIALIZING
;
7267 ap
->pflags
|= ATA_PFLAG_LOADING
;
7268 ata_port_schedule_eh(ap
);
7270 spin_unlock_irqrestore(ap
->lock
, flags
);
7272 /* wait for EH to finish */
7273 ata_port_wait_eh(ap
);
7275 DPRINTK("ata%u: bus probe begin\n", ap
->print_id
);
7276 rc
= ata_bus_probe(ap
);
7277 DPRINTK("ata%u: bus probe end\n", ap
->print_id
);
7280 /* FIXME: do something useful here?
7281 * Current libata behavior will
7282 * tear down everything when
7283 * the module is removed
7284 * or the h/w is unplugged.
7290 /* probes are done, now scan each port's disk(s) */
7291 DPRINTK("host probe begin\n");
7292 for (i
= 0; i
< host
->n_ports
; i
++) {
7293 struct ata_port
*ap
= host
->ports
[i
];
7295 ata_scsi_scan_host(ap
, 1);
7296 ata_lpm_schedule(ap
, ap
->pm_policy
);
7303 * ata_host_activate - start host, request IRQ and register it
7304 * @host: target ATA host
7305 * @irq: IRQ to request
7306 * @irq_handler: irq_handler used when requesting IRQ
7307 * @irq_flags: irq_flags used when requesting IRQ
7308 * @sht: scsi_host_template to use when registering the host
7310 * After allocating an ATA host and initializing it, most libata
7311 * LLDs perform three steps to activate the host - start host,
7312 * request IRQ and register it. This helper takes necessasry
7313 * arguments and performs the three steps in one go.
7315 * An invalid IRQ skips the IRQ registration and expects the host to
7316 * have set polling mode on the port. In this case, @irq_handler
7320 * Inherited from calling layer (may sleep).
7323 * 0 on success, -errno otherwise.
7325 int ata_host_activate(struct ata_host
*host
, int irq
,
7326 irq_handler_t irq_handler
, unsigned long irq_flags
,
7327 struct scsi_host_template
*sht
)
7331 rc
= ata_host_start(host
);
7335 /* Special case for polling mode */
7337 WARN_ON(irq_handler
);
7338 return ata_host_register(host
, sht
);
7341 rc
= devm_request_irq(host
->dev
, irq
, irq_handler
, irq_flags
,
7342 dev_driver_string(host
->dev
), host
);
7346 for (i
= 0; i
< host
->n_ports
; i
++)
7347 ata_port_desc(host
->ports
[i
], "irq %d", irq
);
7349 rc
= ata_host_register(host
, sht
);
7350 /* if failed, just free the IRQ and leave ports alone */
7352 devm_free_irq(host
->dev
, irq
, host
);
7358 * ata_port_detach - Detach ATA port in prepration of device removal
7359 * @ap: ATA port to be detached
7361 * Detach all ATA devices and the associated SCSI devices of @ap;
7362 * then, remove the associated SCSI host. @ap is guaranteed to
7363 * be quiescent on return from this function.
7366 * Kernel thread context (may sleep).
7368 static void ata_port_detach(struct ata_port
*ap
)
7370 unsigned long flags
;
7371 struct ata_link
*link
;
7372 struct ata_device
*dev
;
7374 if (!ap
->ops
->error_handler
)
7377 /* tell EH we're leaving & flush EH */
7378 spin_lock_irqsave(ap
->lock
, flags
);
7379 ap
->pflags
|= ATA_PFLAG_UNLOADING
;
7380 spin_unlock_irqrestore(ap
->lock
, flags
);
7382 ata_port_wait_eh(ap
);
7384 /* EH is now guaranteed to see UNLOADING - EH context belongs
7385 * to us. Disable all existing devices.
7387 ata_port_for_each_link(link
, ap
) {
7388 ata_link_for_each_dev(dev
, link
)
7389 ata_dev_disable(dev
);
7392 /* Final freeze & EH. All in-flight commands are aborted. EH
7393 * will be skipped and retrials will be terminated with bad
7396 spin_lock_irqsave(ap
->lock
, flags
);
7397 ata_port_freeze(ap
); /* won't be thawed */
7398 spin_unlock_irqrestore(ap
->lock
, flags
);
7400 ata_port_wait_eh(ap
);
7401 cancel_rearming_delayed_work(&ap
->hotplug_task
);
7404 /* remove the associated SCSI host */
7405 scsi_remove_host(ap
->scsi_host
);
7409 * ata_host_detach - Detach all ports of an ATA host
7410 * @host: Host to detach
7412 * Detach all ports of @host.
7415 * Kernel thread context (may sleep).
7417 void ata_host_detach(struct ata_host
*host
)
7421 for (i
= 0; i
< host
->n_ports
; i
++)
7422 ata_port_detach(host
->ports
[i
]);
7424 /* the host is dead now, dissociate ACPI */
7425 ata_acpi_dissociate(host
);
7429 * ata_std_ports - initialize ioaddr with standard port offsets.
7430 * @ioaddr: IO address structure to be initialized
7432 * Utility function which initializes data_addr, error_addr,
7433 * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
7434 * device_addr, status_addr, and command_addr to standard offsets
7435 * relative to cmd_addr.
7437 * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
7440 void ata_std_ports(struct ata_ioports
*ioaddr
)
7442 ioaddr
->data_addr
= ioaddr
->cmd_addr
+ ATA_REG_DATA
;
7443 ioaddr
->error_addr
= ioaddr
->cmd_addr
+ ATA_REG_ERR
;
7444 ioaddr
->feature_addr
= ioaddr
->cmd_addr
+ ATA_REG_FEATURE
;
7445 ioaddr
->nsect_addr
= ioaddr
->cmd_addr
+ ATA_REG_NSECT
;
7446 ioaddr
->lbal_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAL
;
7447 ioaddr
->lbam_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAM
;
7448 ioaddr
->lbah_addr
= ioaddr
->cmd_addr
+ ATA_REG_LBAH
;
7449 ioaddr
->device_addr
= ioaddr
->cmd_addr
+ ATA_REG_DEVICE
;
7450 ioaddr
->status_addr
= ioaddr
->cmd_addr
+ ATA_REG_STATUS
;
7451 ioaddr
->command_addr
= ioaddr
->cmd_addr
+ ATA_REG_CMD
;
7458 * ata_pci_remove_one - PCI layer callback for device removal
7459 * @pdev: PCI device that was removed
7461 * PCI layer indicates to libata via this hook that hot-unplug or
7462 * module unload event has occurred. Detach all ports. Resource
7463 * release is handled via devres.
7466 * Inherited from PCI layer (may sleep).
7468 void ata_pci_remove_one(struct pci_dev
*pdev
)
7470 struct device
*dev
= &pdev
->dev
;
7471 struct ata_host
*host
= dev_get_drvdata(dev
);
7473 ata_host_detach(host
);
7476 /* move to PCI subsystem */
7477 int pci_test_config_bits(struct pci_dev
*pdev
, const struct pci_bits
*bits
)
7479 unsigned long tmp
= 0;
7481 switch (bits
->width
) {
7484 pci_read_config_byte(pdev
, bits
->reg
, &tmp8
);
7490 pci_read_config_word(pdev
, bits
->reg
, &tmp16
);
7496 pci_read_config_dword(pdev
, bits
->reg
, &tmp32
);
7507 return (tmp
== bits
->val
) ? 1 : 0;
7511 void ata_pci_device_do_suspend(struct pci_dev
*pdev
, pm_message_t mesg
)
7513 pci_save_state(pdev
);
7514 pci_disable_device(pdev
);
7516 if (mesg
.event
& PM_EVENT_SLEEP
)
7517 pci_set_power_state(pdev
, PCI_D3hot
);
7520 int ata_pci_device_do_resume(struct pci_dev
*pdev
)
7524 pci_set_power_state(pdev
, PCI_D0
);
7525 pci_restore_state(pdev
);
7527 rc
= pcim_enable_device(pdev
);
7529 dev_printk(KERN_ERR
, &pdev
->dev
,
7530 "failed to enable device after resume (%d)\n", rc
);
7534 pci_set_master(pdev
);
7538 int ata_pci_device_suspend(struct pci_dev
*pdev
, pm_message_t mesg
)
7540 struct ata_host
*host
= dev_get_drvdata(&pdev
->dev
);
7543 rc
= ata_host_suspend(host
, mesg
);
7547 ata_pci_device_do_suspend(pdev
, mesg
);
7552 int ata_pci_device_resume(struct pci_dev
*pdev
)
7554 struct ata_host
*host
= dev_get_drvdata(&pdev
->dev
);
7557 rc
= ata_pci_device_do_resume(pdev
);
7559 ata_host_resume(host
);
7562 #endif /* CONFIG_PM */
7564 #endif /* CONFIG_PCI */
7566 static int __init
ata_parse_force_one(char **cur
,
7567 struct ata_force_ent
*force_ent
,
7568 const char **reason
)
7570 /* FIXME: Currently, there's no way to tag init const data and
7571 * using __initdata causes build failure on some versions of
7572 * gcc. Once __initdataconst is implemented, add const to the
7573 * following structure.
7575 static struct ata_force_param force_tbl
[] __initdata
= {
7576 { "40c", .cbl
= ATA_CBL_PATA40
},
7577 { "80c", .cbl
= ATA_CBL_PATA80
},
7578 { "short40c", .cbl
= ATA_CBL_PATA40_SHORT
},
7579 { "unk", .cbl
= ATA_CBL_PATA_UNK
},
7580 { "ign", .cbl
= ATA_CBL_PATA_IGN
},
7581 { "sata", .cbl
= ATA_CBL_SATA
},
7582 { "1.5Gbps", .spd_limit
= 1 },
7583 { "3.0Gbps", .spd_limit
= 2 },
7584 { "noncq", .horkage_on
= ATA_HORKAGE_NONCQ
},
7585 { "ncq", .horkage_off
= ATA_HORKAGE_NONCQ
},
7586 { "pio0", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 0) },
7587 { "pio1", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 1) },
7588 { "pio2", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 2) },
7589 { "pio3", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 3) },
7590 { "pio4", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 4) },
7591 { "pio5", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 5) },
7592 { "pio6", .xfer_mask
= 1 << (ATA_SHIFT_PIO
+ 6) },
7593 { "mwdma0", .xfer_mask
= 1 << (ATA_SHIFT_MWDMA
+ 0) },
7594 { "mwdma1", .xfer_mask
= 1 << (ATA_SHIFT_MWDMA
+ 1) },
7595 { "mwdma2", .xfer_mask
= 1 << (ATA_SHIFT_MWDMA
+ 2) },
7596 { "mwdma3", .xfer_mask
= 1 << (ATA_SHIFT_MWDMA
+ 3) },
7597 { "mwdma4", .xfer_mask
= 1 << (ATA_SHIFT_MWDMA
+ 4) },
7598 { "udma0", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 0) },
7599 { "udma16", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 0) },
7600 { "udma/16", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 0) },
7601 { "udma1", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 1) },
7602 { "udma25", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 1) },
7603 { "udma/25", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 1) },
7604 { "udma2", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 2) },
7605 { "udma33", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 2) },
7606 { "udma/33", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 2) },
7607 { "udma3", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 3) },
7608 { "udma44", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 3) },
7609 { "udma/44", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 3) },
7610 { "udma4", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 4) },
7611 { "udma66", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 4) },
7612 { "udma/66", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 4) },
7613 { "udma5", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 5) },
7614 { "udma100", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 5) },
7615 { "udma/100", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 5) },
7616 { "udma6", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 6) },
7617 { "udma133", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 6) },
7618 { "udma/133", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 6) },
7619 { "udma7", .xfer_mask
= 1 << (ATA_SHIFT_UDMA
+ 7) },
7621 char *start
= *cur
, *p
= *cur
;
7622 char *id
, *val
, *endp
;
7623 const struct ata_force_param
*match_fp
= NULL
;
7624 int nr_matches
= 0, i
;
7626 /* find where this param ends and update *cur */
7627 while (*p
!= '\0' && *p
!= ',')
7638 p
= strchr(start
, ':');
7640 val
= strstrip(start
);
7645 id
= strstrip(start
);
7646 val
= strstrip(p
+ 1);
7649 p
= strchr(id
, '.');
7652 force_ent
->device
= simple_strtoul(p
, &endp
, 10);
7653 if (p
== endp
|| *endp
!= '\0') {
7654 *reason
= "invalid device";
7659 force_ent
->port
= simple_strtoul(id
, &endp
, 10);
7660 if (p
== endp
|| *endp
!= '\0') {
7661 *reason
= "invalid port/link";
7666 /* parse val, allow shortcuts so that both 1.5 and 1.5Gbps work */
7667 for (i
= 0; i
< ARRAY_SIZE(force_tbl
); i
++) {
7668 const struct ata_force_param
*fp
= &force_tbl
[i
];
7670 if (strncasecmp(val
, fp
->name
, strlen(val
)))
7676 if (strcasecmp(val
, fp
->name
) == 0) {
7683 *reason
= "unknown value";
7686 if (nr_matches
> 1) {
7687 *reason
= "ambigious value";
7691 force_ent
->param
= *match_fp
;
7696 static void __init
ata_parse_force_param(void)
7698 int idx
= 0, size
= 1;
7699 int last_port
= -1, last_device
= -1;
7700 char *p
, *cur
, *next
;
7702 /* calculate maximum number of params and allocate force_tbl */
7703 for (p
= ata_force_param_buf
; *p
; p
++)
7707 ata_force_tbl
= kzalloc(sizeof(ata_force_tbl
[0]) * size
, GFP_KERNEL
);
7708 if (!ata_force_tbl
) {
7709 printk(KERN_WARNING
"ata: failed to extend force table, "
7710 "libata.force ignored\n");
7714 /* parse and populate the table */
7715 for (cur
= ata_force_param_buf
; *cur
!= '\0'; cur
= next
) {
7716 const char *reason
= "";
7717 struct ata_force_ent te
= { .port
= -1, .device
= -1 };
7720 if (ata_parse_force_one(&next
, &te
, &reason
)) {
7721 printk(KERN_WARNING
"ata: failed to parse force "
7722 "parameter \"%s\" (%s)\n",
7727 if (te
.port
== -1) {
7728 te
.port
= last_port
;
7729 te
.device
= last_device
;
7732 ata_force_tbl
[idx
++] = te
;
7734 last_port
= te
.port
;
7735 last_device
= te
.device
;
7738 ata_force_tbl_size
= idx
;
7741 static int __init
ata_init(void)
7743 ata_probe_timeout
*= HZ
;
7745 ata_parse_force_param();
7747 ata_wq
= create_workqueue("ata");
7751 ata_aux_wq
= create_singlethread_workqueue("ata_aux");
7753 destroy_workqueue(ata_wq
);
7757 printk(KERN_DEBUG
"libata version " DRV_VERSION
" loaded.\n");
7761 static void __exit
ata_exit(void)
7763 kfree(ata_force_tbl
);
7764 destroy_workqueue(ata_wq
);
7765 destroy_workqueue(ata_aux_wq
);
7768 subsys_initcall(ata_init
);
7769 module_exit(ata_exit
);
7771 static unsigned long ratelimit_time
;
7772 static DEFINE_SPINLOCK(ata_ratelimit_lock
);
7774 int ata_ratelimit(void)
7777 unsigned long flags
;
7779 spin_lock_irqsave(&ata_ratelimit_lock
, flags
);
7781 if (time_after(jiffies
, ratelimit_time
)) {
7783 ratelimit_time
= jiffies
+ (HZ
/5);
7787 spin_unlock_irqrestore(&ata_ratelimit_lock
, flags
);
7793 * ata_wait_register - wait until register value changes
7794 * @reg: IO-mapped register
7795 * @mask: Mask to apply to read register value
7796 * @val: Wait condition
7797 * @interval_msec: polling interval in milliseconds
7798 * @timeout_msec: timeout in milliseconds
7800 * Waiting for some bits of register to change is a common
7801 * operation for ATA controllers. This function reads 32bit LE
7802 * IO-mapped register @reg and tests for the following condition.
7804 * (*@reg & mask) != val
7806 * If the condition is met, it returns; otherwise, the process is
7807 * repeated after @interval_msec until timeout.
7810 * Kernel thread context (may sleep)
7813 * The final register value.
7815 u32
ata_wait_register(void __iomem
*reg
, u32 mask
, u32 val
,
7816 unsigned long interval_msec
,
7817 unsigned long timeout_msec
)
7819 unsigned long timeout
;
7822 tmp
= ioread32(reg
);
7824 /* Calculate timeout _after_ the first read to make sure
7825 * preceding writes reach the controller before starting to
7826 * eat away the timeout.
7828 timeout
= jiffies
+ (timeout_msec
* HZ
) / 1000;
7830 while ((tmp
& mask
) == val
&& time_before(jiffies
, timeout
)) {
7831 msleep(interval_msec
);
7832 tmp
= ioread32(reg
);
7841 static void ata_dummy_noret(struct ata_port
*ap
) { }
7842 static int ata_dummy_ret0(struct ata_port
*ap
) { return 0; }
7843 static void ata_dummy_qc_noret(struct ata_queued_cmd
*qc
) { }
7845 static u8
ata_dummy_check_status(struct ata_port
*ap
)
7850 static unsigned int ata_dummy_qc_issue(struct ata_queued_cmd
*qc
)
7852 return AC_ERR_SYSTEM
;
7855 struct ata_port_operations ata_dummy_port_ops
= {
7856 .check_status
= ata_dummy_check_status
,
7857 .check_altstatus
= ata_dummy_check_status
,
7858 .dev_select
= ata_noop_dev_select
,
7859 .qc_prep
= ata_noop_qc_prep
,
7860 .qc_issue
= ata_dummy_qc_issue
,
7861 .freeze
= ata_dummy_noret
,
7862 .thaw
= ata_dummy_noret
,
7863 .error_handler
= ata_dummy_noret
,
7864 .post_internal_cmd
= ata_dummy_qc_noret
,
7865 .irq_clear
= ata_dummy_noret
,
7866 .port_start
= ata_dummy_ret0
,
7867 .port_stop
= ata_dummy_noret
,
7870 const struct ata_port_info ata_dummy_port_info
= {
7871 .port_ops
= &ata_dummy_port_ops
,
7875 * libata is essentially a library of internal helper functions for
7876 * low-level ATA host controller drivers. As such, the API/ABI is
7877 * likely to change as new drivers are added and updated.
7878 * Do not depend on ABI/API stability.
7880 EXPORT_SYMBOL_GPL(sata_deb_timing_normal
);
7881 EXPORT_SYMBOL_GPL(sata_deb_timing_hotplug
);
7882 EXPORT_SYMBOL_GPL(sata_deb_timing_long
);
7883 EXPORT_SYMBOL_GPL(ata_base_port_ops
);
7884 EXPORT_SYMBOL_GPL(sata_port_ops
);
7885 EXPORT_SYMBOL_GPL(sata_pmp_port_ops
);
7886 EXPORT_SYMBOL_GPL(ata_sff_port_ops
);
7887 EXPORT_SYMBOL_GPL(ata_bmdma_port_ops
);
7888 EXPORT_SYMBOL_GPL(ata_dummy_port_ops
);
7889 EXPORT_SYMBOL_GPL(ata_dummy_port_info
);
7890 EXPORT_SYMBOL_GPL(ata_std_bios_param
);
7891 EXPORT_SYMBOL_GPL(ata_std_ports
);
7892 EXPORT_SYMBOL_GPL(ata_host_init
);
7893 EXPORT_SYMBOL_GPL(ata_host_alloc
);
7894 EXPORT_SYMBOL_GPL(ata_host_alloc_pinfo
);
7895 EXPORT_SYMBOL_GPL(ata_host_start
);
7896 EXPORT_SYMBOL_GPL(ata_host_register
);
7897 EXPORT_SYMBOL_GPL(ata_host_activate
);
7898 EXPORT_SYMBOL_GPL(ata_host_detach
);
7899 EXPORT_SYMBOL_GPL(ata_sg_init
);
7900 EXPORT_SYMBOL_GPL(ata_hsm_move
);
7901 EXPORT_SYMBOL_GPL(ata_qc_complete
);
7902 EXPORT_SYMBOL_GPL(ata_qc_complete_multiple
);
7903 EXPORT_SYMBOL_GPL(ata_qc_issue_prot
);
7904 EXPORT_SYMBOL_GPL(ata_tf_load
);
7905 EXPORT_SYMBOL_GPL(ata_tf_read
);
7906 EXPORT_SYMBOL_GPL(ata_noop_dev_select
);
7907 EXPORT_SYMBOL_GPL(ata_std_dev_select
);
7908 EXPORT_SYMBOL_GPL(sata_print_link_status
);
7909 EXPORT_SYMBOL_GPL(atapi_cmd_type
);
7910 EXPORT_SYMBOL_GPL(ata_tf_to_fis
);
7911 EXPORT_SYMBOL_GPL(ata_tf_from_fis
);
7912 EXPORT_SYMBOL_GPL(ata_pack_xfermask
);
7913 EXPORT_SYMBOL_GPL(ata_unpack_xfermask
);
7914 EXPORT_SYMBOL_GPL(ata_xfer_mask2mode
);
7915 EXPORT_SYMBOL_GPL(ata_xfer_mode2mask
);
7916 EXPORT_SYMBOL_GPL(ata_xfer_mode2shift
);
7917 EXPORT_SYMBOL_GPL(ata_mode_string
);
7918 EXPORT_SYMBOL_GPL(ata_id_xfermask
);
7919 EXPORT_SYMBOL_GPL(ata_check_status
);
7920 EXPORT_SYMBOL_GPL(ata_altstatus
);
7921 EXPORT_SYMBOL_GPL(ata_exec_command
);
7922 EXPORT_SYMBOL_GPL(ata_port_start
);
7923 EXPORT_SYMBOL_GPL(ata_sff_port_start
);
7924 EXPORT_SYMBOL_GPL(ata_interrupt
);
7925 EXPORT_SYMBOL_GPL(ata_do_set_mode
);
7926 EXPORT_SYMBOL_GPL(ata_data_xfer
);
7927 EXPORT_SYMBOL_GPL(ata_data_xfer_noirq
);
7928 EXPORT_SYMBOL_GPL(ata_std_qc_defer
);
7929 EXPORT_SYMBOL_GPL(ata_qc_prep
);
7930 EXPORT_SYMBOL_GPL(ata_dumb_qc_prep
);
7931 EXPORT_SYMBOL_GPL(ata_noop_qc_prep
);
7932 EXPORT_SYMBOL_GPL(ata_bmdma_setup
);
7933 EXPORT_SYMBOL_GPL(ata_bmdma_start
);
7934 EXPORT_SYMBOL_GPL(ata_bmdma_irq_clear
);
7935 EXPORT_SYMBOL_GPL(ata_noop_irq_clear
);
7936 EXPORT_SYMBOL_GPL(ata_bmdma_status
);
7937 EXPORT_SYMBOL_GPL(ata_bmdma_stop
);
7938 EXPORT_SYMBOL_GPL(ata_bmdma_freeze
);
7939 EXPORT_SYMBOL_GPL(ata_bmdma_thaw
);
7940 EXPORT_SYMBOL_GPL(ata_bmdma_drive_eh
);
7941 EXPORT_SYMBOL_GPL(ata_bmdma_error_handler
);
7942 EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd
);
7943 EXPORT_SYMBOL_GPL(ata_port_probe
);
7944 EXPORT_SYMBOL_GPL(ata_dev_disable
);
7945 EXPORT_SYMBOL_GPL(sata_set_spd
);
7946 EXPORT_SYMBOL_GPL(sata_link_debounce
);
7947 EXPORT_SYMBOL_GPL(sata_link_resume
);
7948 EXPORT_SYMBOL_GPL(ata_bus_reset
);
7949 EXPORT_SYMBOL_GPL(ata_std_prereset
);
7950 EXPORT_SYMBOL_GPL(ata_std_softreset
);
7951 EXPORT_SYMBOL_GPL(sata_link_hardreset
);
7952 EXPORT_SYMBOL_GPL(sata_std_hardreset
);
7953 EXPORT_SYMBOL_GPL(ata_std_postreset
);
7954 EXPORT_SYMBOL_GPL(ata_dev_classify
);
7955 EXPORT_SYMBOL_GPL(ata_dev_pair
);
7956 EXPORT_SYMBOL_GPL(ata_port_disable
);
7957 EXPORT_SYMBOL_GPL(ata_ratelimit
);
7958 EXPORT_SYMBOL_GPL(ata_wait_register
);
7959 EXPORT_SYMBOL_GPL(ata_busy_sleep
);
7960 EXPORT_SYMBOL_GPL(ata_wait_after_reset
);
7961 EXPORT_SYMBOL_GPL(ata_wait_ready
);
7962 EXPORT_SYMBOL_GPL(ata_scsi_ioctl
);
7963 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd
);
7964 EXPORT_SYMBOL_GPL(ata_scsi_slave_config
);
7965 EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy
);
7966 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth
);
7967 EXPORT_SYMBOL_GPL(ata_host_intr
);
7968 EXPORT_SYMBOL_GPL(sata_scr_valid
);
7969 EXPORT_SYMBOL_GPL(sata_scr_read
);
7970 EXPORT_SYMBOL_GPL(sata_scr_write
);
7971 EXPORT_SYMBOL_GPL(sata_scr_write_flush
);
7972 EXPORT_SYMBOL_GPL(ata_link_online
);
7973 EXPORT_SYMBOL_GPL(ata_link_offline
);
7975 EXPORT_SYMBOL_GPL(ata_host_suspend
);
7976 EXPORT_SYMBOL_GPL(ata_host_resume
);
7977 #endif /* CONFIG_PM */
7978 EXPORT_SYMBOL_GPL(ata_id_string
);
7979 EXPORT_SYMBOL_GPL(ata_id_c_string
);
7980 EXPORT_SYMBOL_GPL(ata_scsi_simulate
);
7982 EXPORT_SYMBOL_GPL(ata_pio_need_iordy
);
7983 EXPORT_SYMBOL_GPL(ata_timing_find_mode
);
7984 EXPORT_SYMBOL_GPL(ata_timing_compute
);
7985 EXPORT_SYMBOL_GPL(ata_timing_merge
);
7986 EXPORT_SYMBOL_GPL(ata_timing_cycle2mode
);
7989 EXPORT_SYMBOL_GPL(pci_test_config_bits
);
7990 EXPORT_SYMBOL_GPL(ata_pci_init_sff_host
);
7991 EXPORT_SYMBOL_GPL(ata_pci_init_bmdma
);
7992 EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host
);
7993 EXPORT_SYMBOL_GPL(ata_pci_activate_sff_host
);
7994 EXPORT_SYMBOL_GPL(ata_pci_init_one
);
7995 EXPORT_SYMBOL_GPL(ata_pci_remove_one
);
7997 EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend
);
7998 EXPORT_SYMBOL_GPL(ata_pci_device_do_resume
);
7999 EXPORT_SYMBOL_GPL(ata_pci_device_suspend
);
8000 EXPORT_SYMBOL_GPL(ata_pci_device_resume
);
8001 #endif /* CONFIG_PM */
8002 EXPORT_SYMBOL_GPL(ata_pci_default_filter
);
8003 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex
);
8004 #endif /* CONFIG_PCI */
8006 EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch
);
8007 EXPORT_SYMBOL_GPL(sata_pmp_std_prereset
);
8008 EXPORT_SYMBOL_GPL(sata_pmp_std_hardreset
);
8009 EXPORT_SYMBOL_GPL(sata_pmp_std_postreset
);
8010 EXPORT_SYMBOL_GPL(sata_pmp_do_eh
);
8012 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc
);
8013 EXPORT_SYMBOL_GPL(ata_ehi_push_desc
);
8014 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc
);
8015 EXPORT_SYMBOL_GPL(ata_port_desc
);
8017 EXPORT_SYMBOL_GPL(ata_port_pbar_desc
);
8018 #endif /* CONFIG_PCI */
8019 EXPORT_SYMBOL_GPL(ata_port_schedule_eh
);
8020 EXPORT_SYMBOL_GPL(ata_link_abort
);
8021 EXPORT_SYMBOL_GPL(ata_port_abort
);
8022 EXPORT_SYMBOL_GPL(ata_port_freeze
);
8023 EXPORT_SYMBOL_GPL(sata_async_notification
);
8024 EXPORT_SYMBOL_GPL(ata_eh_freeze_port
);
8025 EXPORT_SYMBOL_GPL(ata_eh_thaw_port
);
8026 EXPORT_SYMBOL_GPL(ata_eh_qc_complete
);
8027 EXPORT_SYMBOL_GPL(ata_eh_qc_retry
);
8028 EXPORT_SYMBOL_GPL(ata_do_eh
);
8029 EXPORT_SYMBOL_GPL(ata_irq_on
);
8030 EXPORT_SYMBOL_GPL(ata_dev_try_classify
);
8032 EXPORT_SYMBOL_GPL(ata_cable_40wire
);
8033 EXPORT_SYMBOL_GPL(ata_cable_80wire
);
8034 EXPORT_SYMBOL_GPL(ata_cable_unknown
);
8035 EXPORT_SYMBOL_GPL(ata_cable_ignore
);
8036 EXPORT_SYMBOL_GPL(ata_cable_sata
);