1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>How commands are completed</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="libATA Developer's Guide"><link rel="up" href="libataEH.html" title="Chapter&#160;3.&#160;Error handling"><link rel="prev" href="ch03s03.html" title="How commands are processed"><link rel="next" href="ch03s05.html" title="ata_scsi_error()"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">How commands are completed</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;3.&#160;Error handling</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch03s05.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="idp1120623988"></a>How commands are completed</h2></div></div></div><p>
2	Once issued, all qc's are either completed with
3	ata_qc_complete() or time out.  For commands which are handled
4	by interrupts, ata_host_intr() invokes ata_qc_complete(), and,
5	for PIO tasks, pio_task invokes ata_qc_complete().  In error
6	cases, packet_task may also complete commands.
7	</p><p>
8	ata_qc_complete() does the following.
9	</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
10	DMA memory is unmapped.
11	</p></li><li class="listitem"><p>
12	ATA_QCFLAG_ACTIVE is cleared from qc-&gt;flags.
13	</p></li><li class="listitem"><p>
14	qc-&gt;complete_fn() callback is invoked.  If the return value of
15	the callback is not zero.  Completion is short circuited and
16	ata_qc_complete() returns.
17	</p></li><li class="listitem"><p>
18	__ata_qc_complete() is called, which does
19	   </p><div class="orderedlist"><ol class="orderedlist" type="a"><li class="listitem"><p>
20	   qc-&gt;flags is cleared to zero.
21	   </p></li><li class="listitem"><p>
22	   ap-&gt;active_tag and qc-&gt;tag are poisoned.
23	   </p></li><li class="listitem"><p>
24	   qc-&gt;waiting is cleared &amp; completed (in that order).
25	   </p></li><li class="listitem"><p>
26	   qc is deallocated by clearing appropriate bit in ap-&gt;qactive.
27	   </p></li></ol></div><p>
28	</p></li></ol></div><p>
29	So, it basically notifies upper layer and deallocates qc.  One
30	exception is short-circuit path in #3 which is used by
31	atapi_qc_complete().
32	</p><p>
33	For all non-ATAPI commands, whether it fails or not, almost
34	the same code path is taken and very little error handling
35	takes place.  A qc is completed with success status if it
36	succeeded, with failed status otherwise.
37	</p><p>
38	However, failed ATAPI commands require more handling as
39	REQUEST SENSE is needed to acquire sense data.  If an ATAPI
40	command fails, ata_qc_complete() is invoked with error status,
41	which in turn invokes atapi_qc_complete() via
42	qc-&gt;complete_fn() callback.
43	</p><p>
44	This makes atapi_qc_complete() set scmd-&gt;result to
45	SAM_STAT_CHECK_CONDITION, complete the scmd and return 1.  As
46	the sense data is empty but scmd-&gt;result is CHECK CONDITION,
47	SCSI midlayer will invoke EH for the scmd, and returning 1
48	makes ata_qc_complete() to return without deallocating the qc.
49	This leads us to ata_scsi_error() with partially completed qc.
50	</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="libataEH.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch03s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">How commands are processed&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;ata_scsi_error()</td></tr></table></div></body></html>
51