libata-acpi.c 16 KB

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