]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/ata/libata-acpi.c
libata: Add a drivers/ide style DMA disable
[mirror_ubuntu-hirsute-kernel.git] / drivers / ata / libata-acpi.c
CommitLineData
11ef697b
KCA
1/*
2 * libata-acpi.c
3 * Provides ACPI support for PATA/SATA.
4 *
5 * Copyright (C) 2006 Intel Corp.
6 * Copyright (C) 2006 Randy Dunlap
7 */
8
9#include <linux/ata.h>
10#include <linux/delay.h>
11#include <linux/device.h>
12#include <linux/errno.h>
13#include <linux/kernel.h>
14#include <linux/acpi.h>
15#include <linux/libata.h>
16#include <linux/pci.h>
17#include "libata.h"
18
19#include <acpi/acpi_bus.h>
20#include <acpi/acnames.h>
21#include <acpi/acnamesp.h>
22#include <acpi/acparser.h>
23#include <acpi/acexcep.h>
24#include <acpi/acmacros.h>
25#include <acpi/actypes.h>
26
11ef697b 27#define NO_PORT_MULT 0xffff
fafbae87 28#define SATA_ADR(root,pmp) (((root) << 16) | (pmp))
11ef697b
KCA
29
30#define REGS_PER_GTF 7
4700c4bc
TH
31struct ata_acpi_gtf {
32 u8 tf[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
33} __packed;
11ef697b 34
ca426635
AC
35/*
36 * Helper - belongs in the PCI layer somewhere eventually
37 */
38static int is_pci_dev(struct device *dev)
39{
40 return (dev->bus == &pci_bus_type);
41}
11ef697b 42
d0df8b5d
TH
43/**
44 * ata_acpi_associate_sata_port - associate SATA port with ACPI objects
45 * @ap: target SATA port
46 *
47 * Look up ACPI objects associated with @ap and initialize acpi_handle
48 * fields of @ap, the port and devices accordingly.
49 *
50 * LOCKING:
51 * EH context.
52 *
53 * RETURNS:
54 * 0 on success, -errno on failure.
55 */
56void ata_acpi_associate_sata_port(struct ata_port *ap)
11ef697b 57{
d0df8b5d
TH
58 WARN_ON(!(ap->flags & ATA_FLAG_ACPI_SATA));
59
60 if (!ap->nr_pmp_links) {
61 acpi_integer adr = SATA_ADR(ap->port_no, NO_PORT_MULT);
62
63 ap->link.device->acpi_handle =
64 acpi_get_child(ap->host->acpi_handle, adr);
65 } else {
66 struct ata_link *link;
67
68 ap->link.device->acpi_handle = NULL;
69
70 ata_port_for_each_link(link, ap) {
71 acpi_integer adr = SATA_ADR(ap->port_no, link->pmp);
fafbae87 72
d0df8b5d
TH
73 link->device->acpi_handle =
74 acpi_get_child(ap->host->acpi_handle, adr);
75 }
76 }
11ef697b
KCA
77}
78
fafbae87 79static void ata_acpi_associate_ide_port(struct ata_port *ap)
11ef697b 80{
fafbae87 81 int max_devices, i;
11ef697b 82
fafbae87
TH
83 ap->acpi_handle = acpi_get_child(ap->host->acpi_handle, ap->port_no);
84 if (!ap->acpi_handle)
85 return;
11ef697b 86
fafbae87
TH
87 max_devices = 1;
88 if (ap->flags & ATA_FLAG_SLAVE_POSS)
89 max_devices++;
11ef697b 90
fafbae87 91 for (i = 0; i < max_devices; i++) {
9af5c9c9 92 struct ata_device *dev = &ap->link.device[i];
11ef697b 93
fafbae87 94 dev->acpi_handle = acpi_get_child(ap->acpi_handle, i);
11ef697b 95 }
11ef697b
KCA
96}
97
fafbae87
TH
98/**
99 * ata_acpi_associate - associate ATA host with ACPI objects
100 * @host: target ATA host
101 *
102 * Look up ACPI objects associated with @host and initialize
103 * acpi_handle fields of @host, its ports and devices accordingly.
104 *
105 * LOCKING:
106 * EH context.
107 *
108 * RETURNS:
109 * 0 on success, -errno on failure.
110 */
111void ata_acpi_associate(struct ata_host *host)
11ef697b 112{
fafbae87 113 int i;
11ef697b 114
fafbae87
TH
115 if (!is_pci_dev(host->dev) || libata_noacpi)
116 return;
11ef697b 117
fafbae87
TH
118 host->acpi_handle = DEVICE_ACPI_HANDLE(host->dev);
119 if (!host->acpi_handle)
120 return;
11ef697b 121
fafbae87
TH
122 for (i = 0; i < host->n_ports; i++) {
123 struct ata_port *ap = host->ports[i];
124
125 if (host->ports[0]->flags & ATA_FLAG_ACPI_SATA)
126 ata_acpi_associate_sata_port(ap);
127 else
128 ata_acpi_associate_ide_port(ap);
11ef697b 129 }
11ef697b
KCA
130}
131
64578a3d
TH
132/**
133 * ata_acpi_gtm - execute _GTM
134 * @ap: target ATA port
135 * @gtm: out parameter for _GTM result
136 *
137 * Evaluate _GTM and store the result in @gtm.
138 *
139 * LOCKING:
140 * EH context.
141 *
142 * RETURNS:
143 * 0 on success, -ENOENT if _GTM doesn't exist, -errno on failure.
144 */
145static int ata_acpi_gtm(const struct ata_port *ap, struct ata_acpi_gtm *gtm)
146{
147 struct acpi_buffer output = { .length = ACPI_ALLOCATE_BUFFER };
148 union acpi_object *out_obj;
149 acpi_status status;
150 int rc = 0;
151
152 status = acpi_evaluate_object(ap->acpi_handle, "_GTM", NULL, &output);
153
154 rc = -ENOENT;
155 if (status == AE_NOT_FOUND)
156 goto out_free;
157
158 rc = -EINVAL;
159 if (ACPI_FAILURE(status)) {
160 ata_port_printk(ap, KERN_ERR,
161 "ACPI get timing mode failed (AE 0x%x)\n",
162 status);
163 goto out_free;
164 }
165
166 out_obj = output.pointer;
167 if (out_obj->type != ACPI_TYPE_BUFFER) {
168 ata_port_printk(ap, KERN_WARNING,
169 "_GTM returned unexpected object type 0x%x\n",
170 out_obj->type);
171
172 goto out_free;
173 }
174
175 if (out_obj->buffer.length != sizeof(struct ata_acpi_gtm)) {
176 ata_port_printk(ap, KERN_ERR,
177 "_GTM returned invalid length %d\n",
178 out_obj->buffer.length);
179 goto out_free;
180 }
181
182 memcpy(gtm, out_obj->buffer.pointer, sizeof(struct ata_acpi_gtm));
183 rc = 0;
184 out_free:
185 kfree(output.pointer);
186 return rc;
187}
188
189/**
190 * ata_acpi_stm - execute _STM
191 * @ap: target ATA port
192 * @stm: timing parameter to _STM
193 *
194 * Evaluate _STM with timing parameter @stm.
195 *
196 * LOCKING:
197 * EH context.
198 *
199 * RETURNS:
200 * 0 on success, -ENOENT if _STM doesn't exist, -errno on failure.
201 */
202static int ata_acpi_stm(const struct ata_port *ap, struct ata_acpi_gtm *stm)
203{
204 acpi_status status;
205 struct acpi_object_list input;
206 union acpi_object in_params[3];
207
208 in_params[0].type = ACPI_TYPE_BUFFER;
209 in_params[0].buffer.length = sizeof(struct ata_acpi_gtm);
210 in_params[0].buffer.pointer = (u8 *)stm;
211 /* Buffers for id may need byteswapping ? */
212 in_params[1].type = ACPI_TYPE_BUFFER;
213 in_params[1].buffer.length = 512;
9af5c9c9 214 in_params[1].buffer.pointer = (u8 *)ap->link.device[0].id;
64578a3d
TH
215 in_params[2].type = ACPI_TYPE_BUFFER;
216 in_params[2].buffer.length = 512;
9af5c9c9 217 in_params[2].buffer.pointer = (u8 *)ap->link.device[1].id;
64578a3d
TH
218
219 input.count = 3;
220 input.pointer = in_params;
221
222 status = acpi_evaluate_object(ap->acpi_handle, "_STM", &input, NULL);
223
224 if (status == AE_NOT_FOUND)
225 return -ENOENT;
226 if (ACPI_FAILURE(status)) {
227 ata_port_printk(ap, KERN_ERR,
228 "ACPI set timing mode failed (status=0x%x)\n", status);
229 return -EINVAL;
230 }
231 return 0;
232}
233
11ef697b 234/**
4700c4bc 235 * ata_dev_get_GTF - get the drive bootup default taskfile settings
3a32a8e9 236 * @dev: target ATA device
4700c4bc
TH
237 * @gtf: output parameter for buffer containing _GTF taskfile arrays
238 * @ptr_to_free: pointer which should be freed
11ef697b
KCA
239 *
240 * This applies to both PATA and SATA drives.
241 *
242 * The _GTF method has no input parameters.
243 * It returns a variable number of register set values (registers
244 * hex 1F1..1F7, taskfiles).
245 * The <variable number> is not known in advance, so have ACPI-CA
246 * allocate the buffer as needed and return it, then free it later.
247 *
4700c4bc
TH
248 * LOCKING:
249 * EH context.
250 *
251 * RETURNS:
252 * Number of taskfiles on success, 0 if _GTF doesn't exist or doesn't
253 * contain valid data. -errno on other errors.
11ef697b 254 */
4700c4bc
TH
255static int ata_dev_get_GTF(struct ata_device *dev, struct ata_acpi_gtf **gtf,
256 void **ptr_to_free)
11ef697b 257{
9af5c9c9 258 struct ata_port *ap = dev->link->ap;
3a32a8e9 259 acpi_status status;
3a32a8e9
TH
260 struct acpi_buffer output;
261 union acpi_object *out_obj;
4700c4bc 262 int rc = 0;
11ef697b 263
4700c4bc
TH
264 /* set up output buffer */
265 output.length = ACPI_ALLOCATE_BUFFER;
266 output.pointer = NULL; /* ACPI-CA sets this; save/free it later */
11ef697b 267
11ef697b 268 if (ata_msg_probe(ap))
3a32a8e9 269 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
878d4fed 270 __FUNCTION__, ap->port_no);
11ef697b 271
11ef697b 272 /* _GTF has no input parameters */
4700c4bc
TH
273 status = acpi_evaluate_object(dev->acpi_handle, "_GTF", NULL, &output);
274
11ef697b 275 if (ACPI_FAILURE(status)) {
4700c4bc
TH
276 if (status != AE_NOT_FOUND) {
277 ata_dev_printk(dev, KERN_WARNING,
278 "_GTF evaluation failed (AE 0x%x)\n",
279 status);
280 rc = -EIO;
281 }
282 goto out_free;
11ef697b
KCA
283 }
284
285 if (!output.length || !output.pointer) {
286 if (ata_msg_probe(ap))
3a32a8e9 287 ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: "
11ef697b
KCA
288 "length or ptr is NULL (0x%llx, 0x%p)\n",
289 __FUNCTION__,
290 (unsigned long long)output.length,
291 output.pointer);
4700c4bc 292 goto out_free;
11ef697b
KCA
293 }
294
295 out_obj = output.pointer;
296 if (out_obj->type != ACPI_TYPE_BUFFER) {
69b16a5f
TH
297 ata_dev_printk(dev, KERN_WARNING,
298 "_GTF unexpected object type 0x%x\n",
299 out_obj->type);
4700c4bc
TH
300 rc = -EINVAL;
301 goto out_free;
11ef697b
KCA
302 }
303
4700c4bc 304 if (out_obj->buffer.length % REGS_PER_GTF) {
69b16a5f
TH
305 ata_dev_printk(dev, KERN_WARNING,
306 "unexpected _GTF length (%d)\n",
307 out_obj->buffer.length);
4700c4bc
TH
308 rc = -EINVAL;
309 goto out_free;
11ef697b
KCA
310 }
311
4700c4bc
TH
312 *ptr_to_free = out_obj;
313 *gtf = (void *)out_obj->buffer.pointer;
314 rc = out_obj->buffer.length / REGS_PER_GTF;
315
11ef697b 316 if (ata_msg_probe(ap))
3a32a8e9 317 ata_dev_printk(dev, KERN_DEBUG, "%s: returning "
4700c4bc
TH
318 "gtf=%p, gtf_count=%d, ptr_to_free=%p\n",
319 __FUNCTION__, *gtf, rc, *ptr_to_free);
320 return rc;
321
322 out_free:
323 kfree(output.pointer);
324 return rc;
11ef697b
KCA
325}
326
e1ddb4b6
AC
327/**
328 * ata_acpi_cbl_80wire - Check for 80 wire cable
329 * @ap: Port to check
330 *
331 * Return 1 if the ACPI mode data for this port indicates the BIOS selected
332 * an 80wire mode.
333 */
334
335int ata_acpi_cbl_80wire(struct ata_port *ap)
336{
337 struct ata_acpi_gtm gtm;
338 int valid = 0;
339
340 /* No _GTM data, no information */
341 if (ata_acpi_gtm(ap, &gtm) < 0)
342 return 0;
343
344 /* Split timing, DMA enabled */
345 if ((gtm.flags & 0x11) == 0x11 && gtm.drive[0].dma < 55)
346 valid |= 1;
347 if ((gtm.flags & 0x14) == 0x14 && gtm.drive[1].dma < 55)
348 valid |= 2;
349 /* Shared timing, DMA enabled */
350 if ((gtm.flags & 0x11) == 0x01 && gtm.drive[0].dma < 55)
351 valid |= 1;
352 if ((gtm.flags & 0x14) == 0x04 && gtm.drive[0].dma < 55)
353 valid |= 2;
354
355 /* Drive check */
356 if ((valid & 1) && ata_dev_enabled(&ap->link.device[0]))
357 return 1;
358 if ((valid & 2) && ata_dev_enabled(&ap->link.device[1]))
359 return 1;
360 return 0;
361}
362
363EXPORT_SYMBOL_GPL(ata_acpi_cbl_80wire);
364
11ef697b
KCA
365/**
366 * taskfile_load_raw - send taskfile registers to host controller
3a32a8e9 367 * @dev: target ATA device
11ef697b
KCA
368 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
369 *
370 * Outputs ATA taskfile to standard ATA host controller using MMIO
371 * or PIO as indicated by the ATA_FLAG_MMIO flag.
372 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
373 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
374 * hob_lbal, hob_lbam, and hob_lbah.
375 *
376 * This function waits for idle (!BUSY and !DRQ) after writing
377 * registers. If the control register has a new value, this
378 * function also waits for idle after writing control and before
379 * writing the remaining registers.
380 *
4700c4bc
TH
381 * LOCKING:
382 * EH context.
383 *
384 * RETURNS:
385 * 0 on success, -errno on failure.
11ef697b 386 */
4700c4bc
TH
387static int taskfile_load_raw(struct ata_device *dev,
388 const struct ata_acpi_gtf *gtf)
11ef697b 389{
9af5c9c9 390 struct ata_port *ap = dev->link->ap;
4700c4bc
TH
391 struct ata_taskfile tf, rtf;
392 unsigned int err_mask;
fc16c25f 393
4700c4bc
TH
394 if ((gtf->tf[0] == 0) && (gtf->tf[1] == 0) && (gtf->tf[2] == 0)
395 && (gtf->tf[3] == 0) && (gtf->tf[4] == 0) && (gtf->tf[5] == 0)
396 && (gtf->tf[6] == 0))
397 return 0;
11ef697b 398
3a32a8e9 399 ata_tf_init(dev, &tf);
fc16c25f
JG
400
401 /* convert gtf to tf */
402 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
48be6b18 403 tf.protocol = ATA_PROT_NODATA;
4700c4bc
TH
404 tf.feature = gtf->tf[0]; /* 0x1f1 */
405 tf.nsect = gtf->tf[1]; /* 0x1f2 */
406 tf.lbal = gtf->tf[2]; /* 0x1f3 */
407 tf.lbam = gtf->tf[3]; /* 0x1f4 */
408 tf.lbah = gtf->tf[4]; /* 0x1f5 */
409 tf.device = gtf->tf[5]; /* 0x1f6 */
410 tf.command = gtf->tf[6]; /* 0x1f7 */
411
412 if (ata_msg_probe(ap))
413 ata_dev_printk(dev, KERN_DEBUG, "executing ACPI cmd "
414 "%02x/%02x:%02x:%02x:%02x:%02x:%02x\n",
415 tf.command, tf.feature, tf.nsect,
416 tf.lbal, tf.lbam, tf.lbah, tf.device);
417
418 rtf = tf;
419 err_mask = ata_exec_internal(dev, &rtf, NULL, DMA_NONE, NULL, 0);
420 if (err_mask) {
3a32a8e9 421 ata_dev_printk(dev, KERN_ERR,
4700c4bc
TH
422 "ACPI cmd %02x/%02x:%02x:%02x:%02x:%02x:%02x failed "
423 "(Emask=0x%x Stat=0x%02x Err=0x%02x)\n",
424 tf.command, tf.feature, tf.nsect, tf.lbal, tf.lbam,
425 tf.lbah, tf.device, err_mask, rtf.command, rtf.feature);
426 return -EIO;
427 }
428
429 return 0;
11ef697b
KCA
430}
431
11ef697b
KCA
432/**
433 * ata_acpi_exec_tfs - get then write drive taskfile settings
6746544c 434 * @dev: target ATA device
11ef697b 435 *
6746544c 436 * Evaluate _GTF and excute returned taskfiles.
69b16a5f
TH
437 *
438 * LOCKING:
439 * EH context.
440 *
441 * RETURNS:
6746544c
TH
442 * Number of executed taskfiles on success, 0 if _GTF doesn't exist or
443 * doesn't contain valid data. -errno on other errors.
11ef697b 444 */
6746544c 445static int ata_acpi_exec_tfs(struct ata_device *dev)
11ef697b 446{
6746544c
TH
447 struct ata_acpi_gtf *gtf = NULL;
448 void *ptr_to_free = NULL;
449 int gtf_count, i, rc;
450
451 /* get taskfiles */
452 rc = ata_dev_get_GTF(dev, &gtf, &ptr_to_free);
453 if (rc < 0)
454 return rc;
455 gtf_count = rc;
456
457 /* execute them */
458 for (i = 0, rc = 0; i < gtf_count; i++) {
459 int tmp;
460
461 /* ACPI errors are eventually ignored. Run till the
462 * end even after errors.
463 */
464 tmp = taskfile_load_raw(dev, gtf++);
465 if (!rc)
466 rc = tmp;
11ef697b
KCA
467 }
468
6746544c
TH
469 kfree(ptr_to_free);
470
471 if (rc == 0)
472 return gtf_count;
473 return rc;
11ef697b
KCA
474}
475
7ea1fbc2
KCA
476/**
477 * ata_acpi_push_id - send Identify data to drive
3a32a8e9 478 * @dev: target ATA device
7ea1fbc2
KCA
479 *
480 * _SDD ACPI object: for SATA mode only
481 * Must be after Identify (Packet) Device -- uses its data
482 * ATM this function never returns a failure. It is an optional
483 * method and if it fails for whatever reason, we should still
484 * just keep going.
69b16a5f
TH
485 *
486 * LOCKING:
487 * EH context.
488 *
489 * RETURNS:
490 * 0 on success, -errno on failure.
7ea1fbc2 491 */
6746544c 492static int ata_acpi_push_id(struct ata_device *dev)
7ea1fbc2 493{
9af5c9c9 494 struct ata_port *ap = dev->link->ap;
3a32a8e9 495 int err;
3a32a8e9
TH
496 acpi_status status;
497 struct acpi_object_list input;
498 union acpi_object in_params[1];
7ea1fbc2 499
7ea1fbc2 500 if (ata_msg_probe(ap))
3a32a8e9
TH
501 ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
502 __FUNCTION__, dev->devno, ap->port_no);
7ea1fbc2 503
7ea1fbc2
KCA
504 /* Give the drive Identify data to the drive via the _SDD method */
505 /* _SDD: set up input parameters */
506 input.count = 1;
507 input.pointer = in_params;
508 in_params[0].type = ACPI_TYPE_BUFFER;
3a32a8e9
TH
509 in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS;
510 in_params[0].buffer.pointer = (u8 *)dev->id;
7ea1fbc2
KCA
511 /* Output buffer: _SDD has no output */
512
513 /* It's OK for _SDD to be missing too. */
3a32a8e9 514 swap_buf_le16(dev->id, ATA_ID_WORDS);
fafbae87 515 status = acpi_evaluate_object(dev->acpi_handle, "_SDD", &input, NULL);
3a32a8e9 516 swap_buf_le16(dev->id, ATA_ID_WORDS);
7ea1fbc2
KCA
517
518 err = ACPI_FAILURE(status) ? -EIO : 0;
69b16a5f
TH
519 if (err < 0)
520 ata_dev_printk(dev, KERN_WARNING,
521 "ACPI _SDD failed (AE 0x%x)\n", status);
7ea1fbc2 522
6746544c
TH
523 return err;
524}
525
64578a3d
TH
526/**
527 * ata_acpi_on_suspend - ATA ACPI hook called on suspend
528 * @ap: target ATA port
529 *
530 * This function is called when @ap is about to be suspended. All
531 * devices are already put to sleep but the port_suspend() callback
532 * hasn't been executed yet. Error return from this function aborts
533 * suspend.
534 *
535 * LOCKING:
536 * EH context.
537 *
538 * RETURNS:
539 * 0 on success, -errno on failure.
540 */
541int ata_acpi_on_suspend(struct ata_port *ap)
542{
543 unsigned long flags;
544 int rc;
545
546 /* proceed iff per-port acpi_handle is valid */
547 if (!ap->acpi_handle)
548 return 0;
549 BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA);
550
551 /* store timing parameters */
552 rc = ata_acpi_gtm(ap, &ap->acpi_gtm);
553
554 spin_lock_irqsave(ap->lock, flags);
555 if (rc == 0)
556 ap->pflags |= ATA_PFLAG_GTM_VALID;
557 else
558 ap->pflags &= ~ATA_PFLAG_GTM_VALID;
559 spin_unlock_irqrestore(ap->lock, flags);
560
561 if (rc == -ENOENT)
562 rc = 0;
563 return rc;
564}
565
6746544c
TH
566/**
567 * ata_acpi_on_resume - ATA ACPI hook called on resume
568 * @ap: target ATA port
569 *
570 * This function is called when @ap is resumed - right after port
571 * itself is resumed but before any EH action is taken.
572 *
573 * LOCKING:
574 * EH context.
575 */
576void ata_acpi_on_resume(struct ata_port *ap)
577{
f58229f8 578 struct ata_device *dev;
6746544c 579
64578a3d
TH
580 if (ap->acpi_handle && (ap->pflags & ATA_PFLAG_GTM_VALID)) {
581 BUG_ON(ap->flags & ATA_FLAG_ACPI_SATA);
582
583 /* restore timing parameters */
584 ata_acpi_stm(ap, &ap->acpi_gtm);
585 }
586
6746544c 587 /* schedule _GTF */
f58229f8
TH
588 ata_link_for_each_dev(dev, &ap->link)
589 dev->flags |= ATA_DFLAG_ACPI_PENDING;
7ea1fbc2
KCA
590}
591
6746544c
TH
592/**
593 * ata_acpi_on_devcfg - ATA ACPI hook called on device donfiguration
594 * @dev: target ATA device
595 *
596 * This function is called when @dev is about to be configured.
597 * IDENTIFY data might have been modified after this hook is run.
598 *
599 * LOCKING:
600 * EH context.
601 *
602 * RETURNS:
603 * Positive number if IDENTIFY data needs to be refreshed, 0 if not,
604 * -errno on failure.
605 */
606int ata_acpi_on_devcfg(struct ata_device *dev)
607{
9af5c9c9
TH
608 struct ata_port *ap = dev->link->ap;
609 struct ata_eh_context *ehc = &ap->link.eh_context;
6746544c
TH
610 int acpi_sata = ap->flags & ATA_FLAG_ACPI_SATA;
611 int rc;
612
6746544c
TH
613 if (!dev->acpi_handle)
614 return 0;
615
616 /* do we need to do _GTF? */
617 if (!(dev->flags & ATA_DFLAG_ACPI_PENDING) &&
618 !(acpi_sata && (ehc->i.flags & ATA_EHI_DID_HARDRESET)))
619 return 0;
620
621 /* do _SDD if SATA */
622 if (acpi_sata) {
623 rc = ata_acpi_push_id(dev);
624 if (rc)
625 goto acpi_err;
626 }
627
628 /* do _GTF */
629 rc = ata_acpi_exec_tfs(dev);
630 if (rc < 0)
631 goto acpi_err;
632
633 dev->flags &= ~ATA_DFLAG_ACPI_PENDING;
634
635 /* refresh IDENTIFY page if any _GTF command has been executed */
636 if (rc > 0) {
637 rc = ata_dev_reread_id(dev, 0);
638 if (rc < 0) {
639 ata_dev_printk(dev, KERN_ERR, "failed to IDENTIFY "
640 "after ACPI commands\n");
641 return rc;
642 }
643 }
644
645 return 0;
646
647 acpi_err:
648 /* let EH retry on the first failure, disable ACPI on the second */
649 if (dev->flags & ATA_DFLAG_ACPI_FAILED) {
650 ata_dev_printk(dev, KERN_WARNING, "ACPI on devcfg failed the "
651 "second time, disabling (errno=%d)\n", rc);
652
653 dev->acpi_handle = NULL;
654
655 /* if port is working, request IDENTIFY reload and continue */
656 if (!(ap->pflags & ATA_PFLAG_FROZEN))
657 rc = 1;
658 }
659 dev->flags |= ATA_DFLAG_ACPI_FAILED;
660 return rc;
661}