]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - Documentation/DocBook/libata.tmpl
Merge branch 'bjorn-pci-root-v4-2.6.35' into release
[mirror_ubuntu-artful-kernel.git] / Documentation / DocBook / libata.tmpl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4
5 <book id="libataDevGuide">
6 <bookinfo>
7 <title>libATA Developer's Guide</title>
8
9 <authorgroup>
10 <author>
11 <firstname>Jeff</firstname>
12 <surname>Garzik</surname>
13 </author>
14 </authorgroup>
15
16 <copyright>
17 <year>2003-2006</year>
18 <holder>Jeff Garzik</holder>
19 </copyright>
20
21 <legalnotice>
22 <para>
23 The contents of this file are subject to the Open
24 Software License version 1.1 that can be found at
25 <ulink url="http://www.opensource.org/licenses/osl-1.1.txt">http://www.opensource.org/licenses/osl-1.1.txt</ulink> and is included herein
26 by reference.
27 </para>
28
29 <para>
30 Alternatively, the contents of this file may be used under the terms
31 of the GNU General Public License version 2 (the "GPL") as distributed
32 in the kernel source COPYING file, in which case the provisions of
33 the GPL are applicable instead of the above. If you wish to allow
34 the use of your version of this file only under the terms of the
35 GPL and not to allow others to use your version of this file under
36 the OSL, indicate your decision by deleting the provisions above and
37 replace them with the notice and other provisions required by the GPL.
38 If you do not delete the provisions above, a recipient may use your
39 version of this file under either the OSL or the GPL.
40 </para>
41
42 </legalnotice>
43 </bookinfo>
44
45 <toc></toc>
46
47 <chapter id="libataIntroduction">
48 <title>Introduction</title>
49 <para>
50 libATA is a library used inside the Linux kernel to support ATA host
51 controllers and devices. libATA provides an ATA driver API, class
52 transports for ATA and ATAPI devices, and SCSI&lt;-&gt;ATA translation
53 for ATA devices according to the T10 SAT specification.
54 </para>
55 <para>
56 This Guide documents the libATA driver API, library functions, library
57 internals, and a couple sample ATA low-level drivers.
58 </para>
59 </chapter>
60
61 <chapter id="libataDriverApi">
62 <title>libata Driver API</title>
63 <para>
64 struct ata_port_operations is defined for every low-level libata
65 hardware driver, and it controls how the low-level driver
66 interfaces with the ATA and SCSI layers.
67 </para>
68 <para>
69 FIS-based drivers will hook into the system with ->qc_prep() and
70 ->qc_issue() high-level hooks. Hardware which behaves in a manner
71 similar to PCI IDE hardware may utilize several generic helpers,
72 defining at a bare minimum the bus I/O addresses of the ATA shadow
73 register blocks.
74 </para>
75 <sect1>
76 <title>struct ata_port_operations</title>
77
78 <sect2><title>Disable ATA port</title>
79 <programlisting>
80 void (*port_disable) (struct ata_port *);
81 </programlisting>
82
83 <para>
84 Called from ata_bus_probe() and ata_bus_reset() error paths,
85 as well as when unregistering from the SCSI module (rmmod, hot
86 unplug).
87 This function should do whatever needs to be done to take the
88 port out of use. In most cases, ata_port_disable() can be used
89 as this hook.
90 </para>
91 <para>
92 Called from ata_bus_probe() on a failed probe.
93 Called from ata_bus_reset() on a failed bus reset.
94 Called from ata_scsi_release().
95 </para>
96
97 </sect2>
98
99 <sect2><title>Post-IDENTIFY device configuration</title>
100 <programlisting>
101 void (*dev_config) (struct ata_port *, struct ata_device *);
102 </programlisting>
103
104 <para>
105 Called after IDENTIFY [PACKET] DEVICE is issued to each device
106 found. Typically used to apply device-specific fixups prior to
107 issue of SET FEATURES - XFER MODE, and prior to operation.
108 </para>
109 <para>
110 This entry may be specified as NULL in ata_port_operations.
111 </para>
112
113 </sect2>
114
115 <sect2><title>Set PIO/DMA mode</title>
116 <programlisting>
117 void (*set_piomode) (struct ata_port *, struct ata_device *);
118 void (*set_dmamode) (struct ata_port *, struct ata_device *);
119 void (*post_set_mode) (struct ata_port *);
120 unsigned int (*mode_filter) (struct ata_port *, struct ata_device *, unsigned int);
121 </programlisting>
122
123 <para>
124 Hooks called prior to the issue of SET FEATURES - XFER MODE
125 command. The optional ->mode_filter() hook is called when libata
126 has built a mask of the possible modes. This is passed to the
127 ->mode_filter() function which should return a mask of valid modes
128 after filtering those unsuitable due to hardware limits. It is not
129 valid to use this interface to add modes.
130 </para>
131 <para>
132 dev->pio_mode and dev->dma_mode are guaranteed to be valid when
133 ->set_piomode() and when ->set_dmamode() is called. The timings for
134 any other drive sharing the cable will also be valid at this point.
135 That is the library records the decisions for the modes of each
136 drive on a channel before it attempts to set any of them.
137 </para>
138 <para>
139 ->post_set_mode() is
140 called unconditionally, after the SET FEATURES - XFER MODE
141 command completes successfully.
142 </para>
143
144 <para>
145 ->set_piomode() is always called (if present), but
146 ->set_dma_mode() is only called if DMA is possible.
147 </para>
148
149 </sect2>
150
151 <sect2><title>Taskfile read/write</title>
152 <programlisting>
153 void (*sff_tf_load) (struct ata_port *ap, struct ata_taskfile *tf);
154 void (*sff_tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
155 </programlisting>
156
157 <para>
158 ->tf_load() is called to load the given taskfile into hardware
159 registers / DMA buffers. ->tf_read() is called to read the
160 hardware registers / DMA buffers, to obtain the current set of
161 taskfile register values.
162 Most drivers for taskfile-based hardware (PIO or MMIO) use
163 ata_sff_tf_load() and ata_sff_tf_read() for these hooks.
164 </para>
165
166 </sect2>
167
168 <sect2><title>PIO data read/write</title>
169 <programlisting>
170 void (*sff_data_xfer) (struct ata_device *, unsigned char *, unsigned int, int);
171 </programlisting>
172
173 <para>
174 All bmdma-style drivers must implement this hook. This is the low-level
175 operation that actually copies the data bytes during a PIO data
176 transfer.
177 Typically the driver will choose one of ata_sff_data_xfer_noirq(),
178 ata_sff_data_xfer(), or ata_sff_data_xfer32().
179 </para>
180
181 </sect2>
182
183 <sect2><title>ATA command execute</title>
184 <programlisting>
185 void (*sff_exec_command)(struct ata_port *ap, struct ata_taskfile *tf);
186 </programlisting>
187
188 <para>
189 causes an ATA command, previously loaded with
190 ->tf_load(), to be initiated in hardware.
191 Most drivers for taskfile-based hardware use ata_sff_exec_command()
192 for this hook.
193 </para>
194
195 </sect2>
196
197 <sect2><title>Per-cmd ATAPI DMA capabilities filter</title>
198 <programlisting>
199 int (*check_atapi_dma) (struct ata_queued_cmd *qc);
200 </programlisting>
201
202 <para>
203 Allow low-level driver to filter ATA PACKET commands, returning a status
204 indicating whether or not it is OK to use DMA for the supplied PACKET
205 command.
206 </para>
207 <para>
208 This hook may be specified as NULL, in which case libata will
209 assume that atapi dma can be supported.
210 </para>
211
212 </sect2>
213
214 <sect2><title>Read specific ATA shadow registers</title>
215 <programlisting>
216 u8 (*sff_check_status)(struct ata_port *ap);
217 u8 (*sff_check_altstatus)(struct ata_port *ap);
218 </programlisting>
219
220 <para>
221 Reads the Status/AltStatus ATA shadow register from
222 hardware. On some hardware, reading the Status register has
223 the side effect of clearing the interrupt condition.
224 Most drivers for taskfile-based hardware use
225 ata_sff_check_status() for this hook.
226 </para>
227
228 </sect2>
229
230 <sect2><title>Select ATA device on bus</title>
231 <programlisting>
232 void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
233 </programlisting>
234
235 <para>
236 Issues the low-level hardware command(s) that causes one of N
237 hardware devices to be considered 'selected' (active and
238 available for use) on the ATA bus. This generally has no
239 meaning on FIS-based devices.
240 </para>
241 <para>
242 Most drivers for taskfile-based hardware use
243 ata_sff_dev_select() for this hook.
244 </para>
245
246 </sect2>
247
248 <sect2><title>Private tuning method</title>
249 <programlisting>
250 void (*set_mode) (struct ata_port *ap);
251 </programlisting>
252
253 <para>
254 By default libata performs drive and controller tuning in
255 accordance with the ATA timing rules and also applies blacklists
256 and cable limits. Some controllers need special handling and have
257 custom tuning rules, typically raid controllers that use ATA
258 commands but do not actually do drive timing.
259 </para>
260
261 <warning>
262 <para>
263 This hook should not be used to replace the standard controller
264 tuning logic when a controller has quirks. Replacing the default
265 tuning logic in that case would bypass handling for drive and
266 bridge quirks that may be important to data reliability. If a
267 controller needs to filter the mode selection it should use the
268 mode_filter hook instead.
269 </para>
270 </warning>
271
272 </sect2>
273
274 <sect2><title>Control PCI IDE BMDMA engine</title>
275 <programlisting>
276 void (*bmdma_setup) (struct ata_queued_cmd *qc);
277 void (*bmdma_start) (struct ata_queued_cmd *qc);
278 void (*bmdma_stop) (struct ata_port *ap);
279 u8 (*bmdma_status) (struct ata_port *ap);
280 </programlisting>
281
282 <para>
283 When setting up an IDE BMDMA transaction, these hooks arm
284 (->bmdma_setup), fire (->bmdma_start), and halt (->bmdma_stop)
285 the hardware's DMA engine. ->bmdma_status is used to read the standard
286 PCI IDE DMA Status register.
287 </para>
288
289 <para>
290 These hooks are typically either no-ops, or simply not implemented, in
291 FIS-based drivers.
292 </para>
293 <para>
294 Most legacy IDE drivers use ata_bmdma_setup() for the bmdma_setup()
295 hook. ata_bmdma_setup() will write the pointer to the PRD table to
296 the IDE PRD Table Address register, enable DMA in the DMA Command
297 register, and call exec_command() to begin the transfer.
298 </para>
299 <para>
300 Most legacy IDE drivers use ata_bmdma_start() for the bmdma_start()
301 hook. ata_bmdma_start() will write the ATA_DMA_START flag to the DMA
302 Command register.
303 </para>
304 <para>
305 Many legacy IDE drivers use ata_bmdma_stop() for the bmdma_stop()
306 hook. ata_bmdma_stop() clears the ATA_DMA_START flag in the DMA
307 command register.
308 </para>
309 <para>
310 Many legacy IDE drivers use ata_bmdma_status() as the bmdma_status() hook.
311 </para>
312
313 </sect2>
314
315 <sect2><title>High-level taskfile hooks</title>
316 <programlisting>
317 void (*qc_prep) (struct ata_queued_cmd *qc);
318 int (*qc_issue) (struct ata_queued_cmd *qc);
319 </programlisting>
320
321 <para>
322 Higher-level hooks, these two hooks can potentially supercede
323 several of the above taskfile/DMA engine hooks. ->qc_prep is
324 called after the buffers have been DMA-mapped, and is typically
325 used to populate the hardware's DMA scatter-gather table.
326 Most drivers use the standard ata_qc_prep() helper function, but
327 more advanced drivers roll their own.
328 </para>
329 <para>
330 ->qc_issue is used to make a command active, once the hardware
331 and S/G tables have been prepared. IDE BMDMA drivers use the
332 helper function ata_qc_issue_prot() for taskfile protocol-based
333 dispatch. More advanced drivers implement their own ->qc_issue.
334 </para>
335 <para>
336 ata_qc_issue_prot() calls ->tf_load(), ->bmdma_setup(), and
337 ->bmdma_start() as necessary to initiate a transfer.
338 </para>
339
340 </sect2>
341
342 <sect2><title>Exception and probe handling (EH)</title>
343 <programlisting>
344 void (*eng_timeout) (struct ata_port *ap);
345 void (*phy_reset) (struct ata_port *ap);
346 </programlisting>
347
348 <para>
349 Deprecated. Use ->error_handler() instead.
350 </para>
351
352 <programlisting>
353 void (*freeze) (struct ata_port *ap);
354 void (*thaw) (struct ata_port *ap);
355 </programlisting>
356
357 <para>
358 ata_port_freeze() is called when HSM violations or some other
359 condition disrupts normal operation of the port. A frozen port
360 is not allowed to perform any operation until the port is
361 thawed, which usually follows a successful reset.
362 </para>
363
364 <para>
365 The optional ->freeze() callback can be used for freezing the port
366 hardware-wise (e.g. mask interrupt and stop DMA engine). If a
367 port cannot be frozen hardware-wise, the interrupt handler
368 must ack and clear interrupts unconditionally while the port
369 is frozen.
370 </para>
371 <para>
372 The optional ->thaw() callback is called to perform the opposite of ->freeze():
373 prepare the port for normal operation once again. Unmask interrupts,
374 start DMA engine, etc.
375 </para>
376
377 <programlisting>
378 void (*error_handler) (struct ata_port *ap);
379 </programlisting>
380
381 <para>
382 ->error_handler() is a driver's hook into probe, hotplug, and recovery
383 and other exceptional conditions. The primary responsibility of an
384 implementation is to call ata_do_eh() or ata_bmdma_drive_eh() with a set
385 of EH hooks as arguments:
386 </para>
387
388 <para>
389 'prereset' hook (may be NULL) is called during an EH reset, before any other actions
390 are taken.
391 </para>
392
393 <para>
394 'postreset' hook (may be NULL) is called after the EH reset is performed. Based on
395 existing conditions, severity of the problem, and hardware capabilities,
396 </para>
397
398 <para>
399 Either 'softreset' (may be NULL) or 'hardreset' (may be NULL) will be
400 called to perform the low-level EH reset.
401 </para>
402
403 <programlisting>
404 void (*post_internal_cmd) (struct ata_queued_cmd *qc);
405 </programlisting>
406
407 <para>
408 Perform any hardware-specific actions necessary to finish processing
409 after executing a probe-time or EH-time command via ata_exec_internal().
410 </para>
411
412 </sect2>
413
414 <sect2><title>Hardware interrupt handling</title>
415 <programlisting>
416 irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
417 void (*irq_clear) (struct ata_port *);
418 </programlisting>
419
420 <para>
421 ->irq_handler is the interrupt handling routine registered with
422 the system, by libata. ->irq_clear is called during probe just
423 before the interrupt handler is registered, to be sure hardware
424 is quiet.
425 </para>
426 <para>
427 The second argument, dev_instance, should be cast to a pointer
428 to struct ata_host_set.
429 </para>
430 <para>
431 Most legacy IDE drivers use ata_sff_interrupt() for the
432 irq_handler hook, which scans all ports in the host_set,
433 determines which queued command was active (if any), and calls
434 ata_sff_host_intr(ap,qc).
435 </para>
436 <para>
437 Most legacy IDE drivers use ata_sff_irq_clear() for the
438 irq_clear() hook, which simply clears the interrupt and error
439 flags in the DMA status register.
440 </para>
441
442 </sect2>
443
444 <sect2><title>SATA phy read/write</title>
445 <programlisting>
446 int (*scr_read) (struct ata_port *ap, unsigned int sc_reg,
447 u32 *val);
448 int (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
449 u32 val);
450 </programlisting>
451
452 <para>
453 Read and write standard SATA phy registers. Currently only used
454 if ->phy_reset hook called the sata_phy_reset() helper function.
455 sc_reg is one of SCR_STATUS, SCR_CONTROL, SCR_ERROR, or SCR_ACTIVE.
456 </para>
457
458 </sect2>
459
460 <sect2><title>Init and shutdown</title>
461 <programlisting>
462 int (*port_start) (struct ata_port *ap);
463 void (*port_stop) (struct ata_port *ap);
464 void (*host_stop) (struct ata_host_set *host_set);
465 </programlisting>
466
467 <para>
468 ->port_start() is called just after the data structures for each
469 port are initialized. Typically this is used to alloc per-port
470 DMA buffers / tables / rings, enable DMA engines, and similar
471 tasks. Some drivers also use this entry point as a chance to
472 allocate driver-private memory for ap->private_data.
473 </para>
474 <para>
475 Many drivers use ata_port_start() as this hook or call
476 it from their own port_start() hooks. ata_port_start()
477 allocates space for a legacy IDE PRD table and returns.
478 </para>
479 <para>
480 ->port_stop() is called after ->host_stop(). It's sole function
481 is to release DMA/memory resources, now that they are no longer
482 actively being used. Many drivers also free driver-private
483 data from port at this time.
484 </para>
485 <para>
486 ->host_stop() is called after all ->port_stop() calls
487 have completed. The hook must finalize hardware shutdown, release DMA
488 and other resources, etc.
489 This hook may be specified as NULL, in which case it is not called.
490 </para>
491
492 </sect2>
493
494 </sect1>
495 </chapter>
496
497 <chapter id="libataEH">
498 <title>Error handling</title>
499
500 <para>
501 This chapter describes how errors are handled under libata.
502 Readers are advised to read SCSI EH
503 (Documentation/scsi/scsi_eh.txt) and ATA exceptions doc first.
504 </para>
505
506 <sect1><title>Origins of commands</title>
507 <para>
508 In libata, a command is represented with struct ata_queued_cmd
509 or qc. qc's are preallocated during port initialization and
510 repetitively used for command executions. Currently only one
511 qc is allocated per port but yet-to-be-merged NCQ branch
512 allocates one for each tag and maps each qc to NCQ tag 1-to-1.
513 </para>
514 <para>
515 libata commands can originate from two sources - libata itself
516 and SCSI midlayer. libata internal commands are used for
517 initialization and error handling. All normal blk requests
518 and commands for SCSI emulation are passed as SCSI commands
519 through queuecommand callback of SCSI host template.
520 </para>
521 </sect1>
522
523 <sect1><title>How commands are issued</title>
524
525 <variablelist>
526
527 <varlistentry><term>Internal commands</term>
528 <listitem>
529 <para>
530 First, qc is allocated and initialized using
531 ata_qc_new_init(). Although ata_qc_new_init() doesn't
532 implement any wait or retry mechanism when qc is not
533 available, internal commands are currently issued only during
534 initialization and error recovery, so no other command is
535 active and allocation is guaranteed to succeed.
536 </para>
537 <para>
538 Once allocated qc's taskfile is initialized for the command to
539 be executed. qc currently has two mechanisms to notify
540 completion. One is via qc->complete_fn() callback and the
541 other is completion qc->waiting. qc->complete_fn() callback
542 is the asynchronous path used by normal SCSI translated
543 commands and qc->waiting is the synchronous (issuer sleeps in
544 process context) path used by internal commands.
545 </para>
546 <para>
547 Once initialization is complete, host_set lock is acquired
548 and the qc is issued.
549 </para>
550 </listitem>
551 </varlistentry>
552
553 <varlistentry><term>SCSI commands</term>
554 <listitem>
555 <para>
556 All libata drivers use ata_scsi_queuecmd() as
557 hostt->queuecommand callback. scmds can either be simulated
558 or translated. No qc is involved in processing a simulated
559 scmd. The result is computed right away and the scmd is
560 completed.
561 </para>
562 <para>
563 For a translated scmd, ata_qc_new_init() is invoked to
564 allocate a qc and the scmd is translated into the qc. SCSI
565 midlayer's completion notification function pointer is stored
566 into qc->scsidone.
567 </para>
568 <para>
569 qc->complete_fn() callback is used for completion
570 notification. ATA commands use ata_scsi_qc_complete() while
571 ATAPI commands use atapi_qc_complete(). Both functions end up
572 calling qc->scsidone to notify upper layer when the qc is
573 finished. After translation is completed, the qc is issued
574 with ata_qc_issue().
575 </para>
576 <para>
577 Note that SCSI midlayer invokes hostt->queuecommand while
578 holding host_set lock, so all above occur while holding
579 host_set lock.
580 </para>
581 </listitem>
582 </varlistentry>
583
584 </variablelist>
585 </sect1>
586
587 <sect1><title>How commands are processed</title>
588 <para>
589 Depending on which protocol and which controller are used,
590 commands are processed differently. For the purpose of
591 discussion, a controller which uses taskfile interface and all
592 standard callbacks is assumed.
593 </para>
594 <para>
595 Currently 6 ATA command protocols are used. They can be
596 sorted into the following four categories according to how
597 they are processed.
598 </para>
599
600 <variablelist>
601 <varlistentry><term>ATA NO DATA or DMA</term>
602 <listitem>
603 <para>
604 ATA_PROT_NODATA and ATA_PROT_DMA fall into this category.
605 These types of commands don't require any software
606 intervention once issued. Device will raise interrupt on
607 completion.
608 </para>
609 </listitem>
610 </varlistentry>
611
612 <varlistentry><term>ATA PIO</term>
613 <listitem>
614 <para>
615 ATA_PROT_PIO is in this category. libata currently
616 implements PIO with polling. ATA_NIEN bit is set to turn
617 off interrupt and pio_task on ata_wq performs polling and
618 IO.
619 </para>
620 </listitem>
621 </varlistentry>
622
623 <varlistentry><term>ATAPI NODATA or DMA</term>
624 <listitem>
625 <para>
626 ATA_PROT_ATAPI_NODATA and ATA_PROT_ATAPI_DMA are in this
627 category. packet_task is used to poll BSY bit after
628 issuing PACKET command. Once BSY is turned off by the
629 device, packet_task transfers CDB and hands off processing
630 to interrupt handler.
631 </para>
632 </listitem>
633 </varlistentry>
634
635 <varlistentry><term>ATAPI PIO</term>
636 <listitem>
637 <para>
638 ATA_PROT_ATAPI is in this category. ATA_NIEN bit is set
639 and, as in ATAPI NODATA or DMA, packet_task submits cdb.
640 However, after submitting cdb, further processing (data
641 transfer) is handed off to pio_task.
642 </para>
643 </listitem>
644 </varlistentry>
645 </variablelist>
646 </sect1>
647
648 <sect1><title>How commands are completed</title>
649 <para>
650 Once issued, all qc's are either completed with
651 ata_qc_complete() or time out. For commands which are handled
652 by interrupts, ata_host_intr() invokes ata_qc_complete(), and,
653 for PIO tasks, pio_task invokes ata_qc_complete(). In error
654 cases, packet_task may also complete commands.
655 </para>
656 <para>
657 ata_qc_complete() does the following.
658 </para>
659
660 <orderedlist>
661
662 <listitem>
663 <para>
664 DMA memory is unmapped.
665 </para>
666 </listitem>
667
668 <listitem>
669 <para>
670 ATA_QCFLAG_ACTIVE is clared from qc->flags.
671 </para>
672 </listitem>
673
674 <listitem>
675 <para>
676 qc->complete_fn() callback is invoked. If the return value of
677 the callback is not zero. Completion is short circuited and
678 ata_qc_complete() returns.
679 </para>
680 </listitem>
681
682 <listitem>
683 <para>
684 __ata_qc_complete() is called, which does
685 <orderedlist>
686
687 <listitem>
688 <para>
689 qc->flags is cleared to zero.
690 </para>
691 </listitem>
692
693 <listitem>
694 <para>
695 ap->active_tag and qc->tag are poisoned.
696 </para>
697 </listitem>
698
699 <listitem>
700 <para>
701 qc->waiting is claread &amp; completed (in that order).
702 </para>
703 </listitem>
704
705 <listitem>
706 <para>
707 qc is deallocated by clearing appropriate bit in ap->qactive.
708 </para>
709 </listitem>
710
711 </orderedlist>
712 </para>
713 </listitem>
714
715 </orderedlist>
716
717 <para>
718 So, it basically notifies upper layer and deallocates qc. One
719 exception is short-circuit path in #3 which is used by
720 atapi_qc_complete().
721 </para>
722 <para>
723 For all non-ATAPI commands, whether it fails or not, almost
724 the same code path is taken and very little error handling
725 takes place. A qc is completed with success status if it
726 succeeded, with failed status otherwise.
727 </para>
728 <para>
729 However, failed ATAPI commands require more handling as
730 REQUEST SENSE is needed to acquire sense data. If an ATAPI
731 command fails, ata_qc_complete() is invoked with error status,
732 which in turn invokes atapi_qc_complete() via
733 qc->complete_fn() callback.
734 </para>
735 <para>
736 This makes atapi_qc_complete() set scmd->result to
737 SAM_STAT_CHECK_CONDITION, complete the scmd and return 1. As
738 the sense data is empty but scmd->result is CHECK CONDITION,
739 SCSI midlayer will invoke EH for the scmd, and returning 1
740 makes ata_qc_complete() to return without deallocating the qc.
741 This leads us to ata_scsi_error() with partially completed qc.
742 </para>
743
744 </sect1>
745
746 <sect1><title>ata_scsi_error()</title>
747 <para>
748 ata_scsi_error() is the current transportt->eh_strategy_handler()
749 for libata. As discussed above, this will be entered in two
750 cases - timeout and ATAPI error completion. This function
751 calls low level libata driver's eng_timeout() callback, the
752 standard callback for which is ata_eng_timeout(). It checks
753 if a qc is active and calls ata_qc_timeout() on the qc if so.
754 Actual error handling occurs in ata_qc_timeout().
755 </para>
756 <para>
757 If EH is invoked for timeout, ata_qc_timeout() stops BMDMA and
758 completes the qc. Note that as we're currently in EH, we
759 cannot call scsi_done. As described in SCSI EH doc, a
760 recovered scmd should be either retried with
761 scsi_queue_insert() or finished with scsi_finish_command().
762 Here, we override qc->scsidone with scsi_finish_command() and
763 calls ata_qc_complete().
764 </para>
765 <para>
766 If EH is invoked due to a failed ATAPI qc, the qc here is
767 completed but not deallocated. The purpose of this
768 half-completion is to use the qc as place holder to make EH
769 code reach this place. This is a bit hackish, but it works.
770 </para>
771 <para>
772 Once control reaches here, the qc is deallocated by invoking
773 __ata_qc_complete() explicitly. Then, internal qc for REQUEST
774 SENSE is issued. Once sense data is acquired, scmd is
775 finished by directly invoking scsi_finish_command() on the
776 scmd. Note that as we already have completed and deallocated
777 the qc which was associated with the scmd, we don't need
778 to/cannot call ata_qc_complete() again.
779 </para>
780
781 </sect1>
782
783 <sect1><title>Problems with the current EH</title>
784
785 <itemizedlist>
786
787 <listitem>
788 <para>
789 Error representation is too crude. Currently any and all
790 error conditions are represented with ATA STATUS and ERROR
791 registers. Errors which aren't ATA device errors are treated
792 as ATA device errors by setting ATA_ERR bit. Better error
793 descriptor which can properly represent ATA and other
794 errors/exceptions is needed.
795 </para>
796 </listitem>
797
798 <listitem>
799 <para>
800 When handling timeouts, no action is taken to make device
801 forget about the timed out command and ready for new commands.
802 </para>
803 </listitem>
804
805 <listitem>
806 <para>
807 EH handling via ata_scsi_error() is not properly protected
808 from usual command processing. On EH entrance, the device is
809 not in quiescent state. Timed out commands may succeed or
810 fail any time. pio_task and atapi_task may still be running.
811 </para>
812 </listitem>
813
814 <listitem>
815 <para>
816 Too weak error recovery. Devices / controllers causing HSM
817 mismatch errors and other errors quite often require reset to
818 return to known state. Also, advanced error handling is
819 necessary to support features like NCQ and hotplug.
820 </para>
821 </listitem>
822
823 <listitem>
824 <para>
825 ATA errors are directly handled in the interrupt handler and
826 PIO errors in pio_task. This is problematic for advanced
827 error handling for the following reasons.
828 </para>
829 <para>
830 First, advanced error handling often requires context and
831 internal qc execution.
832 </para>
833 <para>
834 Second, even a simple failure (say, CRC error) needs
835 information gathering and could trigger complex error handling
836 (say, resetting &amp; reconfiguring). Having multiple code
837 paths to gather information, enter EH and trigger actions
838 makes life painful.
839 </para>
840 <para>
841 Third, scattered EH code makes implementing low level drivers
842 difficult. Low level drivers override libata callbacks. If
843 EH is scattered over several places, each affected callbacks
844 should perform its part of error handling. This can be error
845 prone and painful.
846 </para>
847 </listitem>
848
849 </itemizedlist>
850 </sect1>
851 </chapter>
852
853 <chapter id="libataExt">
854 <title>libata Library</title>
855 !Edrivers/ata/libata-core.c
856 </chapter>
857
858 <chapter id="libataInt">
859 <title>libata Core Internals</title>
860 !Idrivers/ata/libata-core.c
861 </chapter>
862
863 <chapter id="libataScsiInt">
864 <title>libata SCSI translation/emulation</title>
865 !Edrivers/ata/libata-scsi.c
866 !Idrivers/ata/libata-scsi.c
867 </chapter>
868
869 <chapter id="ataExceptions">
870 <title>ATA errors and exceptions</title>
871
872 <para>
873 This chapter tries to identify what error/exception conditions exist
874 for ATA/ATAPI devices and describe how they should be handled in
875 implementation-neutral way.
876 </para>
877
878 <para>
879 The term 'error' is used to describe conditions where either an
880 explicit error condition is reported from device or a command has
881 timed out.
882 </para>
883
884 <para>
885 The term 'exception' is either used to describe exceptional
886 conditions which are not errors (say, power or hotplug events), or
887 to describe both errors and non-error exceptional conditions. Where
888 explicit distinction between error and exception is necessary, the
889 term 'non-error exception' is used.
890 </para>
891
892 <sect1 id="excat">
893 <title>Exception categories</title>
894 <para>
895 Exceptions are described primarily with respect to legacy
896 taskfile + bus master IDE interface. If a controller provides
897 other better mechanism for error reporting, mapping those into
898 categories described below shouldn't be difficult.
899 </para>
900
901 <para>
902 In the following sections, two recovery actions - reset and
903 reconfiguring transport - are mentioned. These are described
904 further in <xref linkend="exrec"/>.
905 </para>
906
907 <sect2 id="excatHSMviolation">
908 <title>HSM violation</title>
909 <para>
910 This error is indicated when STATUS value doesn't match HSM
911 requirement during issuing or excution any ATA/ATAPI command.
912 </para>
913
914 <itemizedlist>
915 <title>Examples</title>
916
917 <listitem>
918 <para>
919 ATA_STATUS doesn't contain !BSY &amp;&amp; DRDY &amp;&amp; !DRQ while trying
920 to issue a command.
921 </para>
922 </listitem>
923
924 <listitem>
925 <para>
926 !BSY &amp;&amp; !DRQ during PIO data transfer.
927 </para>
928 </listitem>
929
930 <listitem>
931 <para>
932 DRQ on command completion.
933 </para>
934 </listitem>
935
936 <listitem>
937 <para>
938 !BSY &amp;&amp; ERR after CDB tranfer starts but before the
939 last byte of CDB is transferred. ATA/ATAPI standard states
940 that &quot;The device shall not terminate the PACKET command
941 with an error before the last byte of the command packet has
942 been written&quot; in the error outputs description of PACKET
943 command and the state diagram doesn't include such
944 transitions.
945 </para>
946 </listitem>
947
948 </itemizedlist>
949
950 <para>
951 In these cases, HSM is violated and not much information
952 regarding the error can be acquired from STATUS or ERROR
953 register. IOW, this error can be anything - driver bug,
954 faulty device, controller and/or cable.
955 </para>
956
957 <para>
958 As HSM is violated, reset is necessary to restore known state.
959 Reconfiguring transport for lower speed might be helpful too
960 as transmission errors sometimes cause this kind of errors.
961 </para>
962 </sect2>
963
964 <sect2 id="excatDevErr">
965 <title>ATA/ATAPI device error (non-NCQ / non-CHECK CONDITION)</title>
966
967 <para>
968 These are errors detected and reported by ATA/ATAPI devices
969 indicating device problems. For this type of errors, STATUS
970 and ERROR register values are valid and describe error
971 condition. Note that some of ATA bus errors are detected by
972 ATA/ATAPI devices and reported using the same mechanism as
973 device errors. Those cases are described later in this
974 section.
975 </para>
976
977 <para>
978 For ATA commands, this type of errors are indicated by !BSY
979 &amp;&amp; ERR during command execution and on completion.
980 </para>
981
982 <para>For ATAPI commands,</para>
983
984 <itemizedlist>
985
986 <listitem>
987 <para>
988 !BSY &amp;&amp; ERR &amp;&amp; ABRT right after issuing PACKET
989 indicates that PACKET command is not supported and falls in
990 this category.
991 </para>
992 </listitem>
993
994 <listitem>
995 <para>
996 !BSY &amp;&amp; ERR(==CHK) &amp;&amp; !ABRT after the last
997 byte of CDB is transferred indicates CHECK CONDITION and
998 doesn't fall in this category.
999 </para>
1000 </listitem>
1001
1002 <listitem>
1003 <para>
1004 !BSY &amp;&amp; ERR(==CHK) &amp;&amp; ABRT after the last byte
1005 of CDB is transferred *probably* indicates CHECK CONDITION and
1006 doesn't fall in this category.
1007 </para>
1008 </listitem>
1009
1010 </itemizedlist>
1011
1012 <para>
1013 Of errors detected as above, the followings are not ATA/ATAPI
1014 device errors but ATA bus errors and should be handled
1015 according to <xref linkend="excatATAbusErr"/>.
1016 </para>
1017
1018 <variablelist>
1019
1020 <varlistentry>
1021 <term>CRC error during data transfer</term>
1022 <listitem>
1023 <para>
1024 This is indicated by ICRC bit in the ERROR register and
1025 means that corruption occurred during data transfer. Upto
1026 ATA/ATAPI-7, the standard specifies that this bit is only
1027 applicable to UDMA transfers but ATA/ATAPI-8 draft revision
1028 1f says that the bit may be applicable to multiword DMA and
1029 PIO.
1030 </para>
1031 </listitem>
1032 </varlistentry>
1033
1034 <varlistentry>
1035 <term>ABRT error during data transfer or on completion</term>
1036 <listitem>
1037 <para>
1038 Upto ATA/ATAPI-7, the standard specifies that ABRT could be
1039 set on ICRC errors and on cases where a device is not able
1040 to complete a command. Combined with the fact that MWDMA
1041 and PIO transfer errors aren't allowed to use ICRC bit upto
1042 ATA/ATAPI-7, it seems to imply that ABRT bit alone could
1043 indicate tranfer errors.
1044 </para>
1045 <para>
1046 However, ATA/ATAPI-8 draft revision 1f removes the part
1047 that ICRC errors can turn on ABRT. So, this is kind of
1048 gray area. Some heuristics are needed here.
1049 </para>
1050 </listitem>
1051 </varlistentry>
1052
1053 </variablelist>
1054
1055 <para>
1056 ATA/ATAPI device errors can be further categorized as follows.
1057 </para>
1058
1059 <variablelist>
1060
1061 <varlistentry>
1062 <term>Media errors</term>
1063 <listitem>
1064 <para>
1065 This is indicated by UNC bit in the ERROR register. ATA
1066 devices reports UNC error only after certain number of
1067 retries cannot recover the data, so there's nothing much
1068 else to do other than notifying upper layer.
1069 </para>
1070 <para>
1071 READ and WRITE commands report CHS or LBA of the first
1072 failed sector but ATA/ATAPI standard specifies that the
1073 amount of transferred data on error completion is
1074 indeterminate, so we cannot assume that sectors preceding
1075 the failed sector have been transferred and thus cannot
1076 complete those sectors successfully as SCSI does.
1077 </para>
1078 </listitem>
1079 </varlistentry>
1080
1081 <varlistentry>
1082 <term>Media changed / media change requested error</term>
1083 <listitem>
1084 <para>
1085 &lt;&lt;TODO: fill here&gt;&gt;
1086 </para>
1087 </listitem>
1088 </varlistentry>
1089
1090 <varlistentry><term>Address error</term>
1091 <listitem>
1092 <para>
1093 This is indicated by IDNF bit in the ERROR register.
1094 Report to upper layer.
1095 </para>
1096 </listitem>
1097 </varlistentry>
1098
1099 <varlistentry><term>Other errors</term>
1100 <listitem>
1101 <para>
1102 This can be invalid command or parameter indicated by ABRT
1103 ERROR bit or some other error condition. Note that ABRT
1104 bit can indicate a lot of things including ICRC and Address
1105 errors. Heuristics needed.
1106 </para>
1107 </listitem>
1108 </varlistentry>
1109
1110 </variablelist>
1111
1112 <para>
1113 Depending on commands, not all STATUS/ERROR bits are
1114 applicable. These non-applicable bits are marked with
1115 &quot;na&quot; in the output descriptions but upto ATA/ATAPI-7
1116 no definition of &quot;na&quot; can be found. However,
1117 ATA/ATAPI-8 draft revision 1f describes &quot;N/A&quot; as
1118 follows.
1119 </para>
1120
1121 <blockquote>
1122 <variablelist>
1123 <varlistentry><term>3.2.3.3a N/A</term>
1124 <listitem>
1125 <para>
1126 A keyword the indicates a field has no defined value in
1127 this standard and should not be checked by the host or
1128 device. N/A fields should be cleared to zero.
1129 </para>
1130 </listitem>
1131 </varlistentry>
1132 </variablelist>
1133 </blockquote>
1134
1135 <para>
1136 So, it seems reasonable to assume that &quot;na&quot; bits are
1137 cleared to zero by devices and thus need no explicit masking.
1138 </para>
1139
1140 </sect2>
1141
1142 <sect2 id="excatATAPIcc">
1143 <title>ATAPI device CHECK CONDITION</title>
1144
1145 <para>
1146 ATAPI device CHECK CONDITION error is indicated by set CHK bit
1147 (ERR bit) in the STATUS register after the last byte of CDB is
1148 transferred for a PACKET command. For this kind of errors,
1149 sense data should be acquired to gather information regarding
1150 the errors. REQUEST SENSE packet command should be used to
1151 acquire sense data.
1152 </para>
1153
1154 <para>
1155 Once sense data is acquired, this type of errors can be
1156 handled similary to other SCSI errors. Note that sense data
1157 may indicate ATA bus error (e.g. Sense Key 04h HARDWARE ERROR
1158 &amp;&amp; ASC/ASCQ 47h/00h SCSI PARITY ERROR). In such
1159 cases, the error should be considered as an ATA bus error and
1160 handled according to <xref linkend="excatATAbusErr"/>.
1161 </para>
1162
1163 </sect2>
1164
1165 <sect2 id="excatNCQerr">
1166 <title>ATA device error (NCQ)</title>
1167
1168 <para>
1169 NCQ command error is indicated by cleared BSY and set ERR bit
1170 during NCQ command phase (one or more NCQ commands
1171 outstanding). Although STATUS and ERROR registers will
1172 contain valid values describing the error, READ LOG EXT is
1173 required to clear the error condition, determine which command
1174 has failed and acquire more information.
1175 </para>
1176
1177 <para>
1178 READ LOG EXT Log Page 10h reports which tag has failed and
1179 taskfile register values describing the error. With this
1180 information the failed command can be handled as a normal ATA
1181 command error as in <xref linkend="excatDevErr"/> and all
1182 other in-flight commands must be retried. Note that this
1183 retry should not be counted - it's likely that commands
1184 retried this way would have completed normally if it were not
1185 for the failed command.
1186 </para>
1187
1188 <para>
1189 Note that ATA bus errors can be reported as ATA device NCQ
1190 errors. This should be handled as described in <xref
1191 linkend="excatATAbusErr"/>.
1192 </para>
1193
1194 <para>
1195 If READ LOG EXT Log Page 10h fails or reports NQ, we're
1196 thoroughly screwed. This condition should be treated
1197 according to <xref linkend="excatHSMviolation"/>.
1198 </para>
1199
1200 </sect2>
1201
1202 <sect2 id="excatATAbusErr">
1203 <title>ATA bus error</title>
1204
1205 <para>
1206 ATA bus error means that data corruption occurred during
1207 transmission over ATA bus (SATA or PATA). This type of errors
1208 can be indicated by
1209 </para>
1210
1211 <itemizedlist>
1212
1213 <listitem>
1214 <para>
1215 ICRC or ABRT error as described in <xref linkend="excatDevErr"/>.
1216 </para>
1217 </listitem>
1218
1219 <listitem>
1220 <para>
1221 Controller-specific error completion with error information
1222 indicating transmission error.
1223 </para>
1224 </listitem>
1225
1226 <listitem>
1227 <para>
1228 On some controllers, command timeout. In this case, there may
1229 be a mechanism to determine that the timeout is due to
1230 transmission error.
1231 </para>
1232 </listitem>
1233
1234 <listitem>
1235 <para>
1236 Unknown/random errors, timeouts and all sorts of weirdities.
1237 </para>
1238 </listitem>
1239
1240 </itemizedlist>
1241
1242 <para>
1243 As described above, transmission errors can cause wide variety
1244 of symptoms ranging from device ICRC error to random device
1245 lockup, and, for many cases, there is no way to tell if an
1246 error condition is due to transmission error or not;
1247 therefore, it's necessary to employ some kind of heuristic
1248 when dealing with errors and timeouts. For example,
1249 encountering repetitive ABRT errors for known supported
1250 command is likely to indicate ATA bus error.
1251 </para>
1252
1253 <para>
1254 Once it's determined that ATA bus errors have possibly
1255 occurred, lowering ATA bus transmission speed is one of
1256 actions which may alleviate the problem. See <xref
1257 linkend="exrecReconf"/> for more information.
1258 </para>
1259
1260 </sect2>
1261
1262 <sect2 id="excatPCIbusErr">
1263 <title>PCI bus error</title>
1264
1265 <para>
1266 Data corruption or other failures during transmission over PCI
1267 (or other system bus). For standard BMDMA, this is indicated
1268 by Error bit in the BMDMA Status register. This type of
1269 errors must be logged as it indicates something is very wrong
1270 with the system. Resetting host controller is recommended.
1271 </para>
1272
1273 </sect2>
1274
1275 <sect2 id="excatLateCompletion">
1276 <title>Late completion</title>
1277
1278 <para>
1279 This occurs when timeout occurs and the timeout handler finds
1280 out that the timed out command has completed successfully or
1281 with error. This is usually caused by lost interrupts. This
1282 type of errors must be logged. Resetting host controller is
1283 recommended.
1284 </para>
1285
1286 </sect2>
1287
1288 <sect2 id="excatUnknown">
1289 <title>Unknown error (timeout)</title>
1290
1291 <para>
1292 This is when timeout occurs and the command is still
1293 processing or the host and device are in unknown state. When
1294 this occurs, HSM could be in any valid or invalid state. To
1295 bring the device to known state and make it forget about the
1296 timed out command, resetting is necessary. The timed out
1297 command may be retried.
1298 </para>
1299
1300 <para>
1301 Timeouts can also be caused by transmission errors. Refer to
1302 <xref linkend="excatATAbusErr"/> for more details.
1303 </para>
1304
1305 </sect2>
1306
1307 <sect2 id="excatHoplugPM">
1308 <title>Hotplug and power management exceptions</title>
1309
1310 <para>
1311 &lt;&lt;TODO: fill here&gt;&gt;
1312 </para>
1313
1314 </sect2>
1315
1316 </sect1>
1317
1318 <sect1 id="exrec">
1319 <title>EH recovery actions</title>
1320
1321 <para>
1322 This section discusses several important recovery actions.
1323 </para>
1324
1325 <sect2 id="exrecClr">
1326 <title>Clearing error condition</title>
1327
1328 <para>
1329 Many controllers require its error registers to be cleared by
1330 error handler. Different controllers may have different
1331 requirements.
1332 </para>
1333
1334 <para>
1335 For SATA, it's strongly recommended to clear at least SError
1336 register during error handling.
1337 </para>
1338 </sect2>
1339
1340 <sect2 id="exrecRst">
1341 <title>Reset</title>
1342
1343 <para>
1344 During EH, resetting is necessary in the following cases.
1345 </para>
1346
1347 <itemizedlist>
1348
1349 <listitem>
1350 <para>
1351 HSM is in unknown or invalid state
1352 </para>
1353 </listitem>
1354
1355 <listitem>
1356 <para>
1357 HBA is in unknown or invalid state
1358 </para>
1359 </listitem>
1360
1361 <listitem>
1362 <para>
1363 EH needs to make HBA/device forget about in-flight commands
1364 </para>
1365 </listitem>
1366
1367 <listitem>
1368 <para>
1369 HBA/device behaves weirdly
1370 </para>
1371 </listitem>
1372
1373 </itemizedlist>
1374
1375 <para>
1376 Resetting during EH might be a good idea regardless of error
1377 condition to improve EH robustness. Whether to reset both or
1378 either one of HBA and device depends on situation but the
1379 following scheme is recommended.
1380 </para>
1381
1382 <itemizedlist>
1383
1384 <listitem>
1385 <para>
1386 When it's known that HBA is in ready state but ATA/ATAPI
1387 device is in unknown state, reset only device.
1388 </para>
1389 </listitem>
1390
1391 <listitem>
1392 <para>
1393 If HBA is in unknown state, reset both HBA and device.
1394 </para>
1395 </listitem>
1396
1397 </itemizedlist>
1398
1399 <para>
1400 HBA resetting is implementation specific. For a controller
1401 complying to taskfile/BMDMA PCI IDE, stopping active DMA
1402 transaction may be sufficient iff BMDMA state is the only HBA
1403 context. But even mostly taskfile/BMDMA PCI IDE complying
1404 controllers may have implementation specific requirements and
1405 mechanism to reset themselves. This must be addressed by
1406 specific drivers.
1407 </para>
1408
1409 <para>
1410 OTOH, ATA/ATAPI standard describes in detail ways to reset
1411 ATA/ATAPI devices.
1412 </para>
1413
1414 <variablelist>
1415
1416 <varlistentry><term>PATA hardware reset</term>
1417 <listitem>
1418 <para>
1419 This is hardware initiated device reset signalled with
1420 asserted PATA RESET- signal. There is no standard way to
1421 initiate hardware reset from software although some
1422 hardware provides registers that allow driver to directly
1423 tweak the RESET- signal.
1424 </para>
1425 </listitem>
1426 </varlistentry>
1427
1428 <varlistentry><term>Software reset</term>
1429 <listitem>
1430 <para>
1431 This is achieved by turning CONTROL SRST bit on for at
1432 least 5us. Both PATA and SATA support it but, in case of
1433 SATA, this may require controller-specific support as the
1434 second Register FIS to clear SRST should be transmitted
1435 while BSY bit is still set. Note that on PATA, this resets
1436 both master and slave devices on a channel.
1437 </para>
1438 </listitem>
1439 </varlistentry>
1440
1441 <varlistentry><term>EXECUTE DEVICE DIAGNOSTIC command</term>
1442 <listitem>
1443 <para>
1444 Although ATA/ATAPI standard doesn't describe exactly, EDD
1445 implies some level of resetting, possibly similar level
1446 with software reset. Host-side EDD protocol can be handled
1447 with normal command processing and most SATA controllers
1448 should be able to handle EDD's just like other commands.
1449 As in software reset, EDD affects both devices on a PATA
1450 bus.
1451 </para>
1452 <para>
1453 Although EDD does reset devices, this doesn't suit error
1454 handling as EDD cannot be issued while BSY is set and it's
1455 unclear how it will act when device is in unknown/weird
1456 state.
1457 </para>
1458 </listitem>
1459 </varlistentry>
1460
1461 <varlistentry><term>ATAPI DEVICE RESET command</term>
1462 <listitem>
1463 <para>
1464 This is very similar to software reset except that reset
1465 can be restricted to the selected device without affecting
1466 the other device sharing the cable.
1467 </para>
1468 </listitem>
1469 </varlistentry>
1470
1471 <varlistentry><term>SATA phy reset</term>
1472 <listitem>
1473 <para>
1474 This is the preferred way of resetting a SATA device. In
1475 effect, it's identical to PATA hardware reset. Note that
1476 this can be done with the standard SCR Control register.
1477 As such, it's usually easier to implement than software
1478 reset.
1479 </para>
1480 </listitem>
1481 </varlistentry>
1482
1483 </variablelist>
1484
1485 <para>
1486 One more thing to consider when resetting devices is that
1487 resetting clears certain configuration parameters and they
1488 need to be set to their previous or newly adjusted values
1489 after reset.
1490 </para>
1491
1492 <para>
1493 Parameters affected are.
1494 </para>
1495
1496 <itemizedlist>
1497
1498 <listitem>
1499 <para>
1500 CHS set up with INITIALIZE DEVICE PARAMETERS (seldomly used)
1501 </para>
1502 </listitem>
1503
1504 <listitem>
1505 <para>
1506 Parameters set with SET FEATURES including transfer mode setting
1507 </para>
1508 </listitem>
1509
1510 <listitem>
1511 <para>
1512 Block count set with SET MULTIPLE MODE
1513 </para>
1514 </listitem>
1515
1516 <listitem>
1517 <para>
1518 Other parameters (SET MAX, MEDIA LOCK...)
1519 </para>
1520 </listitem>
1521
1522 </itemizedlist>
1523
1524 <para>
1525 ATA/ATAPI standard specifies that some parameters must be
1526 maintained across hardware or software reset, but doesn't
1527 strictly specify all of them. Always reconfiguring needed
1528 parameters after reset is required for robustness. Note that
1529 this also applies when resuming from deep sleep (power-off).
1530 </para>
1531
1532 <para>
1533 Also, ATA/ATAPI standard requires that IDENTIFY DEVICE /
1534 IDENTIFY PACKET DEVICE is issued after any configuration
1535 parameter is updated or a hardware reset and the result used
1536 for further operation. OS driver is required to implement
1537 revalidation mechanism to support this.
1538 </para>
1539
1540 </sect2>
1541
1542 <sect2 id="exrecReconf">
1543 <title>Reconfigure transport</title>
1544
1545 <para>
1546 For both PATA and SATA, a lot of corners are cut for cheap
1547 connectors, cables or controllers and it's quite common to see
1548 high transmission error rate. This can be mitigated by
1549 lowering transmission speed.
1550 </para>
1551
1552 <para>
1553 The following is a possible scheme Jeff Garzik suggested.
1554 </para>
1555
1556 <blockquote>
1557 <para>
1558 If more than $N (3?) transmission errors happen in 15 minutes,
1559 </para>
1560 <itemizedlist>
1561 <listitem>
1562 <para>
1563 if SATA, decrease SATA PHY speed. if speed cannot be decreased,
1564 </para>
1565 </listitem>
1566 <listitem>
1567 <para>
1568 decrease UDMA xfer speed. if at UDMA0, switch to PIO4,
1569 </para>
1570 </listitem>
1571 <listitem>
1572 <para>
1573 decrease PIO xfer speed. if at PIO3, complain, but continue
1574 </para>
1575 </listitem>
1576 </itemizedlist>
1577 </blockquote>
1578
1579 </sect2>
1580
1581 </sect1>
1582
1583 </chapter>
1584
1585 <chapter id="PiixInt">
1586 <title>ata_piix Internals</title>
1587 !Idrivers/ata/ata_piix.c
1588 </chapter>
1589
1590 <chapter id="SILInt">
1591 <title>sata_sil Internals</title>
1592 !Idrivers/ata/sata_sil.c
1593 </chapter>
1594
1595 <chapter id="libataThanks">
1596 <title>Thanks</title>
1597 <para>
1598 The bulk of the ATA knowledge comes thanks to long conversations with
1599 Andre Hedrick (www.linux-ide.org), and long hours pondering the ATA
1600 and SCSI specifications.
1601 </para>
1602 <para>
1603 Thanks to Alan Cox for pointing out similarities
1604 between SATA and SCSI, and in general for motivation to hack on
1605 libata.
1606 </para>
1607 <para>
1608 libata's device detection
1609 method, ata_pio_devchk, and in general all the early probing was
1610 based on extensive study of Hale Landis's probe/reset code in his
1611 ATADRVR driver (www.ata-atapi.com).
1612 </para>
1613 </chapter>
1614
1615 </book>