<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>

<book id="libataDevGuide">
 <bookinfo>
  <title>libATA Developer's Guide</title>
  
  <authorgroup>
   <author>
    <firstname>Jeff</firstname>
    <surname>Garzik</surname>
   </author>
  </authorgroup>

  <copyright>
   <year>2003-2005</year>
   <holder>Jeff Garzik</holder>
  </copyright>

  <legalnotice>
   <para>
   The contents of this file are subject to the Open
   Software License version 1.1 that can be found at
   <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
   by reference.
   </para>

   <para>
   Alternatively, the contents of this file may be used under the terms
   of the GNU General Public License version 2 (the "GPL") as distributed
   in the kernel source COPYING file, in which case the provisions of
   the GPL are applicable instead of the above.  If you wish to allow
   the use of your version of this file only under the terms of the
   GPL and not to allow others to use your version of this file under
   the OSL, indicate your decision by deleting the provisions above and
   replace them with the notice and other provisions required by the GPL.
   If you do not delete the provisions above, a recipient may use your
   version of this file under either the OSL or the GPL.
   </para>

  </legalnotice>
 </bookinfo>

<toc></toc>

  <chapter id="libataIntroduction">
     <title>Introduction</title>
  <para>
  libATA is a library used inside the Linux kernel to support ATA host
  controllers and devices.  libATA provides an ATA driver API, class
  transports for ATA and ATAPI devices, and SCSI&lt;-&gt;ATA translation
  for ATA devices according to the T10 SAT specification.
  </para>
  <para>
  This Guide documents the libATA driver API, library functions, library
  internals, and a couple sample ATA low-level drivers.
  </para>
  </chapter>

  <chapter id="libataDriverApi">
     <title>libata Driver API</title>
     <para>
     struct ata_port_operations is defined for every low-level libata
     hardware driver, and it controls how the low-level driver
     interfaces with the ATA and SCSI layers.
     </para>
     <para>
     FIS-based drivers will hook into the system with ->qc_prep() and
     ->qc_issue() high-level hooks.  Hardware which behaves in a manner
     similar to PCI IDE hardware may utilize several generic helpers,
     defining at a bare minimum the bus I/O addresses of the ATA shadow
     register blocks.
     </para>
     <sect1>
        <title>struct ata_port_operations</title>

	<sect2><title>Disable ATA port</title>
	<programlisting>
void (*port_disable) (struct ata_port *);
	</programlisting>

	<para>
	Called from ata_bus_probe() and ata_bus_reset() error paths,
	as well as when unregistering from the SCSI module (rmmod, hot
	unplug).
	This function should do whatever needs to be done to take the
	port out of use.  In most cases, ata_port_disable() can be used
	as this hook.
	</para>
	<para>
	Called from ata_bus_probe() on a failed probe.
	Called from ata_bus_reset() on a failed bus reset.
	Called from ata_scsi_release().
	</para>

	</sect2>

	<sect2><title>Post-IDENTIFY device configuration</title>
	<programlisting>
void (*dev_config) (struct ata_port *, struct ata_device *);
	</programlisting>

	<para>
	Called after IDENTIFY [PACKET] DEVICE is issued to each device
	found.  Typically used to apply device-specific fixups prior to
	issue of SET FEATURES - XFER MODE, and prior to operation.
	</para>
	<para>
	Called by ata_device_add() after ata_dev_identify() determines
	a device is present.
	</para>
	<para>
	This entry may be specified as NULL in ata_port_operations.
	</para>

	</sect2>

	<sect2><title>Set PIO/DMA mode</title>
	<programlisting>
void (*set_piomode) (struct ata_port *, struct ata_device *);
void (*set_dmamode) (struct ata_port *, struct ata_device *);
void (*post_set_mode) (struct ata_port *);
unsigned int (*mode_filter) (struct ata_port *, struct ata_device *, unsigned int);
	</programlisting>

	<para>
	Hooks called prior to the issue of SET FEATURES - XFER MODE
	command.  The optional ->mode_filter() hook is called when libata
	has built a mask of the possible modes. This is passed to the 
	->mode_filter() function which should return a mask of valid modes
	after filtering those unsuitable due to hardware limits. It is not
	valid to use this interface to add modes.
	</para>
	<para>
	dev->pio_mode and dev->dma_mode are guaranteed to be valid when
	->set_piomode() and when ->set_dmamode() is called. The timings for
	any other drive sharing the cable will also be valid at this point.
	That is the library records the decisions for the modes of each
	drive on a channel before it attempts to set any of them.
	</para>
	<para>
	->post_set_mode() is
	called unconditionally, after the SET FEATURES - XFER MODE
	command completes successfully.
	</para>

	<para>
	->set_piomode() is always called (if present), but
	->set_dma_mode() is only called if DMA is possible.
	</para>

	</sect2>

	<sect2><title>Taskfile read/write</title>
	<programlisting>
void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf);
void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
	</programlisting>

	<para>
	->tf_load() is called to load the given taskfile into hardware
	registers / DMA buffers.  ->tf_read() is called to read the
	hardware registers / DMA buffers, to obtain the current set of
	taskfile register values.
	Most drivers for taskfile-based hardware (PIO or MMIO) use
	ata_tf_load() and ata_tf_read() for these hooks.
	</para>

	</sect2>

	<sect2><title>ATA command execute</title>
	<programlisting>
void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf);
	</programlisting>

	<para>
	causes an ATA command, previously loaded with
	->tf_load(), to be initiated in hardware.
	Most drivers for taskfile-based hardware use ata_exec_command()
	for this hook.
	</para>

	</sect2>

	<sect2><title>Per-cmd ATAPI DMA capabilities filter</title>
	<programlisting>
int (*check_atapi_dma) (struct ata_queued_cmd *qc);
	</programlisting>

	<para>
Allow low-level driver to filter ATA PACKET commands, returning a status
indicating whether or not it is OK to use DMA for the supplied PACKET
command.
	</para>
	<para>
	This hook may be specified as NULL, in which case libata will
	assume that atapi dma can be supported.
	</para>

	</sect2>

	<sect2><title>Read specific ATA shadow registers</title>
	<programlisting>
u8   (*check_status)(struct ata_port *ap);
u8   (*check_altstatus)(struct ata_port *ap);
u8   (*check_err)(struct ata_port *ap);
	</programlisting>

	<para>
	Reads the Status/AltStatus/Error ATA shadow register from
	hardware.  On some hardware, reading the Status register has
	the side effect of clearing the interrupt condition.
	Most drivers for taskfile-based hardware use
	ata_check_status() for this hook.
	</para>
	<para>
	Note that because this is called from ata_device_add(), at
	least a dummy function that clears device interrupts must be
	provided for all drivers, even if the controller doesn't
	actually have a taskfile status register.
	</para>

	</sect2>

	<sect2><title>Select ATA device on bus</title>
	<programlisting>
void (*dev_select)(struct ata_port *ap, unsigned int device);
	</programlisting>

	<para>
	Issues the low-level hardware command(s) that causes one of N
	hardware devices to be considered 'selected' (active and
	available for use) on the ATA bus.  This generally has no
	meaning on FIS-based devices.
	</para>
	<para>
	Most drivers for taskfile-based hardware use
	ata_std_dev_select() for this hook.  Controllers which do not
	support second drives on a port (such as SATA contollers) will
	use ata_noop_dev_select().
	</para>

	</sect2>

	<sect2><title>Private tuning method</title>
	<programlisting>
void (*set_mode) (struct ata_port *ap);
	</programlisting>

	<para>
	By default libata performs drive and controller tuning in
	accordance with the ATA timing rules and also applies blacklists
	and cable limits. Some controllers need special handling and have
	custom tuning rules, typically raid controllers that use ATA
	commands but do not actually do drive timing.
	</para>

	<warning>
	<para>
	This hook should not be used to replace the standard controller
	tuning logic when a controller has quirks. Replacing the default
	tuning logic in that case would bypass handling for drive and
	bridge quirks that may be important to data reliability. If a
	controller needs to filter the mode selection it should use the
	mode_filter hook instead.
	</para>
	</warning>

	</sect2>

	<sect2><title>Reset ATA bus</title>
	<programlisting>
void (*phy_reset) (struct ata_port *ap);
	</programlisting>

	<para>
	The very first step in the probe phase.  Actions vary depending
	on the bus type, typically.  After waking up the device and probing
	for device presence (PATA and SATA), typically a soft reset
	(SRST) will be performed.  Drivers typically use the helper
	functions ata_bus_reset() or sata_phy_reset() for this hook.
	Many SATA drivers use sata_phy_reset() or call it from within
	their own phy_reset() functions.
	</para>

	</sect2>

	<sect2><title>Control PCI IDE BMDMA engine</title>
	<programlisting>
void (*bmdma_setup) (struct ata_queued_cmd *qc);
void (*bmdma_start) (struct ata_queued_cmd *qc);
void (*bmdma_stop) (struct ata_port *ap);
u8   (*bmdma_status) (struct ata_port *ap);
	</programlisting>

	<para>
When setting up an IDE BMDMA transaction, these hooks arm
(->bmdma_setup), fire (->bmdma_start), and halt (->bmdma_stop)
the hardware's DMA engine.  ->bmdma_status is used to read the standard
PCI IDE DMA Status register.
	</para>

	<para>
These hooks are typically either no-ops, or simply not implemented, in
FIS-based drivers.
	</para>
	<para>
Most legacy IDE drivers use ata_bmdma_setup() for the bmdma_setup()
hook.  ata_bmdma_setup() will write the pointer to the PRD table to
the IDE PRD Table Address register, enable DMA in the DMA Command
register, and call exec_command() to begin the transfer.
	</para>
	<para>
Most legacy IDE drivers use ata_bmdma_start() for the bmdma_start()
hook.  ata_bmdma_start() will write the ATA_DMA_START flag to the DMA
Command register.
	</para>
	<para>
Many legacy IDE drivers use ata_bmdma_stop() for the bmdma_stop()
hook.  ata_bmdma_stop() clears the ATA_DMA_START flag in the DMA
command register.
	</para>
	<para>
Many legacy IDE drivers use ata_bmdma_status() as the bmdma_status() hook.
	</para>

	</sect2>

	<sect2><title>High-level taskfile hooks</title>
	<programlisting>
void (*qc_prep) (struct ata_queued_cmd *qc);
int (*qc_issue) (struct ata_queued_cmd *qc);
	</programlisting>

	<para>
	Higher-level hooks, these two hooks can potentially supercede
	several of the above taskfile/DMA engine hooks.  ->qc_prep is
	called after the buffers have been DMA-mapped, and is typically
	used to populate the hardware's DMA scatter-gather table.
	Most drivers use the standard ata_qc_prep() helper function, but
	more advanced drivers roll their own.
	</para>
	<para>
	->qc_issue is used to make a command active, once the hardware
	and S/G tables have been prepared.  IDE BMDMA drivers use the
	helper function ata_qc_issue_prot() for taskfile protocol-based
	dispatch.  More advanced drivers implement their own ->qc_issue.
	</para>
	<para>
	ata_qc_issue_prot() calls ->tf_load(), ->bmdma_setup(), and
	->bmdma_start() as necessary to initiate a transfer.
	</para>

	</sect2>

	<sect2><title>Timeout (error) handling</title>
	<programlisting>
void (*eng_timeout) (struct ata_port *ap);
	</programlisting>

	<para>
This is a high level error handling function, called from the
error handling thread, when a command times out.  Most newer
hardware will implement its own error handling code here.  IDE BMDMA
drivers may use the helper function ata_eng_timeout().
	</para>

	</sect2>

	<sect2><title>Hardware interrupt handling</title>
	<programlisting>
irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
void (*irq_clear) (struct ata_port *);
	</programlisting>

	<para>
	->irq_handler is the interrupt handling routine registered with
	the system, by libata.  ->irq_clear is called during probe just
	before the interrupt handler is registered, to be sure hardware
	is quiet.
	</para>
	<para>
	The second argument, dev_instance, should be cast to a pointer
	to struct ata_host_set.
	</para>
	<para>
	Most legacy IDE drivers use ata_interrupt() for the
	irq_handler hook, which scans all ports in the host_set,
	determines which queued command was active (if any), and calls
	ata_host_intr(ap,qc).
	</para>
	<para>
	Most legacy IDE drivers use ata_bmdma_irq_clear() for the
	irq_clear() hook, which simply clears the interrupt and error
	flags in the DMA status register.
	</para>

	</sect2>

	<sect2><title>SATA phy read/write</title>
	<programlisting>
u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg);
void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
                   u32 val);
	</programlisting>

	<para>
	Read and write standard SATA phy registers.  Currently only used
	if ->phy_reset hook called the sata_phy_reset() helper function.
	sc_reg is one of SCR_STATUS, SCR_CONTROL, SCR_ERROR, or SCR_ACTIVE.
	</para>

	</sect2>

	<sect2><title>Init and shutdown</title>
	<programlisting>
int (*port_start) (struct ata_port *ap);
void (*port_stop) (struct ata_port *ap);
void (*host_stop) (struct ata_host_set *host_set);
	</programlisting>

	<para>
	->port_start() is called just after the data structures for each
	port are initialized.  Typically this is used to alloc per-port
	DMA buffers / tables / rings, enable DMA engines, and similar
	tasks.  Some drivers also use this entry point as a chance to
	allocate driver-private memory for ap->private_data.
	</para>
	<para>
	Many drivers use ata_port_start() as this hook or call
	it from their own port_start() hooks.  ata_port_start()
	allocates space for a legacy IDE PRD table and returns.
	</para>
	<para>
	->port_stop() is called after ->host_stop().  It's sole function
	is to release DMA/memory resources, now that they are no longer
	actively being used.  Many drivers also free driver-private
	data from port at this time.
	</para>
	<para>
	Many drivers use ata_port_stop() as this hook, which frees the
	PRD table.
	</para>
	<para>
	->host_stop() is called after all ->port_stop() calls
have completed.  The hook must finalize hardware shutdown, release DMA
and other resources, etc.
	This hook may be specified as NULL, in which case it is not called.
	</para>

	</sect2>

     </sect1>
  </chapter>

  <chapter id="libataEH">
        <title>Error handling</title>

	<para>
	This chapter describes how errors are handled under libata.
	Readers are advised to read SCSI EH
	(Documentation/scsi/scsi_eh.txt) and ATA exceptions doc first.
	</para>

	<sect1><title>Origins of commands</title>
	<para>
	In libata, a command is represented with struct ata_queued_cmd
	or qc.  qc's are preallocated during port initialization and
	repetitively used for command executions.  Currently only one
	qc is allocated per port but yet-to-be-merged NCQ branch
	allocates one for each tag and maps each qc to NCQ tag 1-to-1.
	</para>
	<para>
	libata commands can originate from two sources - libata itself
	and SCSI midlayer.  libata internal commands are used for
	initialization and error handling.  All normal blk requests
	and commands for SCSI emulation are passed as SCSI commands
	through queuecommand callback of SCSI host template.
	</para>
	</sect1>

	<sect1><title>How commands are issued</title>

	<variablelist>

	<varlistentry><term>Internal commands</term>
	<listitem>
	<para>
	First, qc is allocated and initialized using
	ata_qc_new_init().  Although ata_qc_new_init() doesn't
	implement any wait or retry mechanism when qc is not
	available, internal commands are currently issued only during
	initialization and error recovery, so no other command is
	active and allocation is guaranteed to succeed.
	</para>
	<para>
	Once allocated qc's taskfile is initialized for the command to
	be executed.  qc currently has two mechanisms to notify
	completion.  One is via qc->complete_fn() callback and the
	other is completion qc->waiting.  qc->complete_fn() callback
	is the asynchronous path used by normal SCSI translated
	commands and qc->waiting is the synchronous (issuer sleeps in
	process context) path used by internal commands.
	</para>
	<para>
	Once initialization is complete, host_set lock is acquired
	and the qc is issued.
	</para>
	</listitem>
	</varlistentry>

	<varlistentry><term>SCSI commands</term>
	<listitem>
	<para>
	All libata drivers use ata_scsi_queuecmd() as
	hostt->queuecommand callback.  scmds can either be simulated
	or translated.  No qc is involved in processing a simulated
	scmd.  The result is computed right away and the scmd is
	completed.
	</para>
	<para>
	For a translated scmd, ata_qc_new_init() is invoked to
	allocate a qc and the scmd is translated into the qc.  SCSI
	midlayer's completion notification function pointer is stored
	into qc->scsidone.
	</para>
	<para>
	qc->complete_fn() callback is used for completion
	notification.  ATA commands use ata_scsi_qc_complete() while
	ATAPI commands use atapi_qc_complete().  Both functions end up
	calling qc->scsidone to notify upper layer when the qc is
	finished.  After translation is completed, the qc is issued
	with ata_qc_issue().
	</para>
	<para>
	Note that SCSI midlayer invokes hostt->queuecommand while
	holding host_set lock, so all above occur while holding
	host_set lock.
	</para>
	</listitem>
	</varlistentry>

	</variablelist>
	</sect1>

	<sect1><title>How commands are processed</title>
	<para>
	Depending on which protocol and which controller are used,
	commands are processed differently.  For the purpose of
	discussion, a controller which uses taskfile interface and all
	standard callbacks is assumed.
	</para>
	<para>
	Currently 6 ATA command protocols are used.  They can be
	sorted into the following four categories according to how
	they are processed.
	</para>

	<variablelist>
	   <varlistentry><term>ATA NO DATA or DMA</term>
	   <listitem>
	   <para>
	   ATA_PROT_NODATA and ATA_PROT_DMA fall into this category.
	   These types of commands don't require any software
	   intervention once issued.  Device will raise interrupt on
	   completion.
	   </para>
	   </listitem>
	   </varlistentry>

	   <varlistentry><term>ATA PIO</term>
	   <listitem>
	   <para>
	   ATA_PROT_PIO is in this category.  libata currently
	   implements PIO with polling.  ATA_NIEN bit is set to turn
	   off interrupt and pio_task on ata_wq performs polling and
	   IO.
	   </para>
	   </listitem>
	   </varlistentry>

	   <varlistentry><term>ATAPI NODATA or DMA</term>
	   <listitem>
	   <para>
	   ATA_PROT_ATAPI_NODATA and ATA_PROT_ATAPI_DMA are in this
	   category.  packet_task is used to poll BSY bit after
	   issuing PACKET command.  Once BSY is turned off by the
	   device, packet_task transfers CDB and hands off processing
	   to interrupt handler.
	   </para>
	   </listitem>
	   </varlistentry>

	   <varlistentry><term>ATAPI PIO</term>
	   <listitem>
	   <para>
	   ATA_PROT_ATAPI is in this category.  ATA_NIEN bit is set
	   and, as in ATAPI NODATA or DMA, packet_task submits cdb.
	   However, after submitting cdb, further processing (data
	   transfer) is handed off to pio_task.
	   </para>
	   </listitem>
	   </varlistentry>
	</variablelist>
        </sect1>

	<sect1><title>How commands are completed</title>
	<para>
	Once issued, all qc's are either completed with
	ata_qc_complete() or time out.  For commands which are handled
	by interrupts, ata_host_intr() invokes ata_qc_complete(), and,
	for PIO tasks, pio_task invokes ata_qc_complete().  In error
	cases, packet_task may also complete commands.
	</para>
	<para>
	ata_qc_complete() does the following.
	</para>

	<orderedlist>

	<listitem>
	<para>
	DMA memory is unmapped.
	</para>
	</listitem>

	<listitem>
	<para>
	ATA_QCFLAG_ACTIVE is clared from qc->flags.
	</para>
	</listitem>

	<listitem>
	<para>
	qc->complete_fn() callback is invoked.  If the return value of
	the callback is not zero.  Completion is short circuited and
	ata_qc_complete() returns.
	</para>
	</listitem>

	<listitem>
	<para>
	__ata_qc_complete() is called, which does
	   <orderedlist>

	   <listitem>
	   <para>
	   qc->flags is cleared to zero.
	   </para>
	   </listitem>

	   <listitem>
	   <para>
	   ap->active_tag and qc->tag are poisoned.
	   </para>
	   </listitem>

	   <listitem>
	   <para>
	   qc->waiting is claread &amp; completed (in that order).
	   </para>
	   </listitem>

	   <listitem>
	   <para>
	   qc is deallocated by clearing appropriate bit in ap->qactive.
	   </para>
	   </listitem>

	   </orderedlist>
	</para>
	</listitem>

	</orderedlist>

	<para>
	So, it basically notifies upper layer and deallocates qc.  One
	exception is short-circuit path in #3 which is used by
	atapi_qc_complete().
	</para>
	<para>
	For all non-ATAPI commands, whether it fails or not, almost
	the same code path is taken and very little error handling
	takes place.  A qc is completed with success status if it
	succeeded, with failed status otherwise.
	</para>
	<para>
	However, failed ATAPI commands require more handling as
	REQUEST SENSE is needed to acquire sense data.  If an ATAPI
	command fails, ata_qc_complete() is invoked with error status,
	which in turn invokes atapi_qc_complete() via
	qc->complete_fn() callback.
	</para>
	<para>
	This makes atapi_qc_complete() set scmd->result to
	SAM_STAT_CHECK_CONDITION, complete the scmd and return 1.  As
	the sense data is empty but scmd->result is CHECK CONDITION,
	SCSI midlayer will invoke EH for the scmd, and returning 1
	makes ata_qc_complete() to return without deallocating the qc.
	This leads us to ata_scsi_error() with partially completed qc.
	</para>

	</sect1>

	<sect1><title>ata_scsi_error()</title>
	<para>
	ata_scsi_error() is the current transportt->eh_strategy_handler()
	for libata.  As discussed above, this will be entered in two
	cases - timeout and ATAPI error completion.  This function
	calls low level libata driver's eng_timeout() callback, the
	standard callback for which is ata_eng_timeout().  It checks
	if a qc is active and calls ata_qc_timeout() on the qc if so.
	Actual error handling occurs in ata_qc_timeout().
	</para>
	<para>
	If EH is invoked for timeout, ata_qc_timeout() stops BMDMA and
	completes the qc.  Note that as we're currently in EH, we
	cannot call scsi_done.  As described in SCSI EH doc, a
	recovered scmd should be either retried with
	scsi_queue_insert() or finished with scsi_finish_command().
	Here, we override qc->scsidone with scsi_finish_command() and
	calls ata_qc_complete().
	</para>
	<para>
	If EH is invoked due to a failed ATAPI qc, the qc here is
	completed but not deallocated.  The purpose of this
	half-completion is to use the qc as place holder to make EH
	code reach this place.  This is a bit hackish, but it works.
	</para>
	<para>
	Once control reaches here, the qc is deallocated by invoking
	__ata_qc_complete() explicitly.  Then, internal qc for REQUEST
	SENSE is issued.  Once sense data is acquired, scmd is
	finished by directly invoking scsi_finish_command() on the
	scmd.  Note that as we already have completed and deallocated
	the qc which was associated with the scmd, we don't need
	to/cannot call ata_qc_complete() again.
	</para>

	</sect1>

	<sect1><title>Problems with the current EH</title>

	<itemizedlist>

	<listitem>
	<para>
	Error representation is too crude.  Currently any and all
	error conditions are represented with ATA STATUS and ERROR
	registers.  Errors which aren't ATA device errors are treated
	as ATA device errors by setting ATA_ERR bit.  Better error
	descriptor which can properly represent ATA and other
	errors/exceptions is needed.
	</para>
	</listitem>

	<listitem>
	<para>
	When handling timeouts, no action is taken to make device
	forget about the timed out command and ready for new commands.
	</para>
	</listitem>

	<listitem>
	<para>
	EH handling via ata_scsi_error() is not properly protected
	from usual command processing.  On EH entrance, the device is
	not in quiescent state.  Timed out commands may succeed or
	fail any time.  pio_task and atapi_task may still be running.
	</para>
	</listitem>

	<listitem>
	<para>
	Too weak error recovery.  Devices / controllers causing HSM
	mismatch errors and other errors quite often require reset to
	return to known state.  Also, advanced error handling is
	necessary to support features like NCQ and hotplug.
	</para>
	</listitem>

	<listitem>
	<para>
	ATA errors are directly handled in the interrupt handler and
	PIO errors in pio_task.  This is problematic for advanced
	error handling for the following reasons.
	</para>
	<para>
	First, advanced error handling often requires context and
	internal qc execution.
	</para>
	<para>
	Second, even a simple failure (say, CRC error) needs
	information gathering and could trigger complex error handling
	(say, resetting &amp; reconfiguring).  Having multiple code
	paths to gather information, enter EH and trigger actions
	makes life painful.
	</para>
	<para>
	Third, scattered EH code makes implementing low level drivers
	difficult.  Low level drivers override libata callbacks.  If
	EH is scattered over several places, each affected callbacks
	should perform its part of error handling.  This can be error
	prone and painful.
	</para>
	</listitem>

	</itemizedlist>
	</sect1>
  </chapter>

  <chapter id="libataExt">
     <title>libata Library</title>
<!-- drivers/scsi/libata-core.c -->
<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-tf-to-fis">ata_tf_to_fis</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_tf_to_fis</refname>
 <refpurpose>
   Convert ATA taskfile to SATA FIS structure
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_tf_to_fis </function></funcdef>
   <paramdef>const struct ata_taskfile * <parameter>tf</parameter></paramdef>
   <paramdef>u8 * <parameter>fis</parameter></paramdef>
   <paramdef>u8 <parameter>pmp</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>tf</parameter></term>
   <listitem>
    <para>
     Taskfile to convert
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>fis</parameter></term>
   <listitem>
    <para>
     Buffer into which data will output
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>pmp</parameter></term>
   <listitem>
    <para>
     Port multiplier port
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Converts a standard ATA taskfile to a Serial ATA
   FIS structure (Register - Host to Device).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-tf-from-fis">ata_tf_from_fis</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_tf_from_fis</refname>
 <refpurpose>
      Convert SATA FIS to ATA taskfile
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_tf_from_fis </function></funcdef>
   <paramdef>const u8 * <parameter>fis</parameter></paramdef>
   <paramdef>struct ata_taskfile * <parameter>tf</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>fis</parameter></term>
   <listitem>
    <para>
     Buffer from which data will be input
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>tf</parameter></term>
   <listitem>
    <para>
     Taskfile to output
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Converts a serial ATA FIS structure to a standard ATA taskfile.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-classify">ata_dev_classify</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_classify</refname>
 <refpurpose>
      determine device type based on ATA-spec signature
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_dev_classify </function></funcdef>
   <paramdef>const struct ata_taskfile * <parameter>tf</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>tf</parameter></term>
   <listitem>
    <para>
     ATA taskfile register set for device to be identified
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Determine from taskfile register contents whether a device is
   ATA or ATAPI, as per <quote>Signature and persistence</quote> section
   of ATA/PI spec (volume 1, sect 5.14).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Device type, <constant>ATA_DEV_ATA</constant>, <constant>ATA_DEV_ATAPI</constant>, or <constant>ATA_DEV_UNKNOWN</constant>
   the event of failure.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-id-string">ata_id_string</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_id_string</refname>
 <refpurpose>
      Convert IDENTIFY DEVICE page into string
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_id_string </function></funcdef>
   <paramdef>const u16 * <parameter>id</parameter></paramdef>
   <paramdef>unsigned char * <parameter>s</parameter></paramdef>
   <paramdef>unsigned int <parameter>ofs</parameter></paramdef>
   <paramdef>unsigned int <parameter>len</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>id</parameter></term>
   <listitem>
    <para>
     IDENTIFY DEVICE results we will examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>s</parameter></term>
   <listitem>
    <para>
     string into which data is output
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>ofs</parameter></term>
   <listitem>
    <para>
     offset into identify device page
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>len</parameter></term>
   <listitem>
    <para>
     length of string to return. must be an even number.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   The strings in the IDENTIFY DEVICE page are broken up into
   16-bit chunks.  Run through the string, and output each
   8-bit chunk linearly, regardless of platform.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-id-c-string">ata_id_c_string</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_id_c_string</refname>
 <refpurpose>
      Convert IDENTIFY DEVICE page into C string
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_id_c_string </function></funcdef>
   <paramdef>const u16 * <parameter>id</parameter></paramdef>
   <paramdef>unsigned char * <parameter>s</parameter></paramdef>
   <paramdef>unsigned int <parameter>ofs</parameter></paramdef>
   <paramdef>unsigned int <parameter>len</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>id</parameter></term>
   <listitem>
    <para>
     IDENTIFY DEVICE results we will examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>s</parameter></term>
   <listitem>
    <para>
     string into which data is output
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>ofs</parameter></term>
   <listitem>
    <para>
     offset into identify device page
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>len</parameter></term>
   <listitem>
    <para>
     length of string to return. must be an odd number.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function is identical to ata_id_string except that it
   trims trailing spaces and terminates the resulting string with
   null.  <parameter>len</parameter> must be actual maximum length (even number) + 1.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-noop-dev-select">ata_noop_dev_select</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_noop_dev_select</refname>
 <refpurpose>
      Select device 0/1 on ATA bus
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_noop_dev_select </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to manipulate
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     ATA device (numbered from zero) to select
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function performs no actual function.
   </para><para>

   May be used as the <function>dev_select</function> entry in ata_port_operations.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-dev-select">ata_std_dev_select</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_dev_select</refname>
 <refpurpose>
      Select device 0/1 on ATA bus
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_std_dev_select </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to manipulate
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     ATA device (numbered from zero) to select
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Use the method defined in the ATA specification to
   make either device 0, or device 1, active on the
   ATA channel.  Works with both PIO and MMIO.
   </para><para>

   May be used as the <function>dev_select</function> entry in ata_port_operations.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-queue-task">ata_port_queue_task</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_queue_task</refname>
 <refpurpose>
      Queue port_task
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_port_queue_task </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>void (*<parameter>fn</parameter>)
     <funcparams>void *</funcparams></paramdef>
   <paramdef>void * <parameter>data</parameter></paramdef>
   <paramdef>unsigned long <parameter>delay</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     The ata_port to queue port_task for
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>fn</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>data</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>delay</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Schedule <parameter>fn</parameter>(<parameter>data</parameter>) for execution after <parameter>delay</parameter> jiffies using
   port_task.  There is one port_task per port and it's the
   user(low level driver)'s responsibility to make sure that only
   one task is active at any given time.
   </para><para>

   libata core layer takes care of synchronization between
   port_task and EH.  <function>ata_port_queue_task</function> may be ignored for EH
   synchronization.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-pio-need-iordy">ata_pio_need_iordy</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_pio_need_iordy</refname>
 <refpurpose>
     	check if iordy needed
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_pio_need_iordy </function></funcdef>
   <paramdef>const struct ata_device * <parameter>adev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>adev</parameter></term>
   <listitem>
    <para>
     ATA device
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Check if the current speed of the device requires IORDY. Used
   by various controllers for chip configuration.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-probe">ata_port_probe</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_probe</refname>
 <refpurpose>
      Mark port as enabled
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_port_probe </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port for which we indicate enablement
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Modify <parameter>ap</parameter> data structure such that the system
   thinks that the entire port is enabled.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   host_set lock, or some other form of
   serialization.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API---sata-phy-reset">__sata_phy_reset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>__sata_phy_reset</refname>
 <refpurpose>
      Wake/reset a low-level SATA PHY
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>__sata_phy_reset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     SATA port associated with target SATA PHY.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function issues commands to standard SATA Sxxx
   PHY registers, to wake up the phy (and device), and
   clear any reset condition.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-sata-phy-reset">sata_phy_reset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>sata_phy_reset</refname>
 <refpurpose>
      Reset SATA bus.
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>sata_phy_reset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     SATA port associated with target SATA PHY.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function resets the SATA bus, and then probes
   the bus for devices.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-pair">ata_dev_pair</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_pair</refname>
 <refpurpose>
     	return other device on cable
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>struct ata_device * <function>ata_dev_pair </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>adev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>adev</parameter></term>
   <listitem>
    <para>
     device
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Obtain the other device on the same cable, or if none is
   present NULL is returned
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-disable">ata_port_disable</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_disable</refname>
 <refpurpose>
      Disable port.
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_port_disable </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port to be disabled.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Modify <parameter>ap</parameter> data structure such that the system
   thinks that the entire port is disabled, and should
   never attempt to probe or communicate with devices
   on this port.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   host_set lock, or some other form of
   serialization.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-busy-sleep">ata_busy_sleep</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_busy_sleep</refname>
 <refpurpose>
      sleep until BSY clears, or timeout
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_busy_sleep </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned long <parameter>tmout_pat</parameter></paramdef>
   <paramdef>unsigned long <parameter>tmout</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port containing status register to be polled
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>tmout_pat</parameter></term>
   <listitem>
    <para>
     impatience timeout
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>tmout</parameter></term>
   <listitem>
    <para>
     overall timeout
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Sleep until ATA Status register bit BSY clears,
   or a timeout occurs.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-bus-reset">ata_bus_reset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_bus_reset</refname>
 <refpurpose>
      reset host port and associated ATA channel
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_bus_reset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to reset
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This is typically the first time we actually start issuing
   commands to the ATA channel.  We wait for BSY to clear, then
   issue EXECUTE DEVICE DIAGNOSTIC command, polling for its
   result.  Determine what devices, if any, are on the channel
   by looking at the device 0/1 error register.  Look at the signature
   stored in each device's taskfile registers, to determine if
   the device is ATA or ATAPI.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
   Obtains host_set lock.
</para>
</refsect1>
<refsect1>
<title>SIDE EFFECTS</title>
<para>
   Sets ATA_FLAG_PORT_DISABLED if bus reset fails.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-probeinit">ata_std_probeinit</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_probeinit</refname>
 <refpurpose>
      initialize probing
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_std_probeinit </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to be probed
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   <parameter>ap</parameter> is about to be probed.  Initialize it.  This function is
   to be used as standard callback for <function>ata_drive_probe_reset</function>.
   </para><para>

   NOTE!!! Do not use this function as probeinit if a low level
   driver implements only hardreset.  Just pass NULL as probeinit
   in that case.  Using this function is probably okay but doing
   so makes reset sequence different from the original
   -&gt;phy_reset implementation and Jeff nervous.  :-P
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-softreset">ata_std_softreset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_softreset</refname>
 <refpurpose>
      reset host port via ATA SRST
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_std_softreset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>int <parameter>verbose</parameter></paramdef>
   <paramdef>unsigned int * <parameter>classes</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to reset
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>verbose</parameter></term>
   <listitem>
    <para>
     fail verbosely
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>classes</parameter></term>
   <listitem>
    <para>
     resulting classes of attached devices
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Reset host port using ATA SRST.  This function is to be used
   as standard callback for ata_drive_*<function>_reset</function> functions.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -errno otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-sata-std-hardreset">sata_std_hardreset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>sata_std_hardreset</refname>
 <refpurpose>
      reset host port via SATA phy reset
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>sata_std_hardreset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>int <parameter>verbose</parameter></paramdef>
   <paramdef>unsigned int * <parameter>class</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to reset
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>verbose</parameter></term>
   <listitem>
    <para>
     fail verbosely
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>class</parameter></term>
   <listitem>
    <para>
     resulting class of attached device
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   SATA phy-reset host port using DET bits of SControl register.
   This function is to be used as standard callback for
   ata_drive_*<function>_reset</function>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -errno otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-postreset">ata_std_postreset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_postreset</refname>
 <refpurpose>
      standard postreset callback
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_std_postreset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int * <parameter>classes</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     the target ata_port
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>classes</parameter></term>
   <listitem>
    <para>
     classes of attached devices
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function is invoked after a successful reset.  Note that
   the device might have been reset more than once using
   different reset methods before postreset is invoked.
   </para><para>

   This function is to be used as standard callback for
   ata_drive_*<function>_reset</function>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-probe-reset">ata_std_probe_reset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_probe_reset</refname>
 <refpurpose>
      standard probe reset method
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_std_probe_reset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int * <parameter>classes</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     prot to perform probe-reset
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>classes</parameter></term>
   <listitem>
    <para>
     resulting classes of attached devices
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   The stock off-the-shelf -&gt;probe_reset method.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -errno otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-drive-probe-reset">ata_drive_probe_reset</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_drive_probe_reset</refname>
 <refpurpose>
      Perform probe reset with given methods
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_drive_probe_reset </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>ata_probeinit_fn_t <parameter>probeinit</parameter></paramdef>
   <paramdef>ata_reset_fn_t <parameter>softreset</parameter></paramdef>
   <paramdef>ata_reset_fn_t <parameter>hardreset</parameter></paramdef>
   <paramdef>ata_postreset_fn_t <parameter>postreset</parameter></paramdef>
   <paramdef>unsigned int * <parameter>classes</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to reset
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>probeinit</parameter></term>
   <listitem>
    <para>
     probeinit method (can be NULL)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>softreset</parameter></term>
   <listitem>
    <para>
     softreset method (can be NULL)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>hardreset</parameter></term>
   <listitem>
    <para>
     hardreset method (can be NULL)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>postreset</parameter></term>
   <listitem>
    <para>
     postreset method (can be NULL)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>classes</parameter></term>
   <listitem>
    <para>
     resulting classes of attached devices
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Reset the specified port and classify attached devices using
   given methods.  This function prefers softreset but tries all
   possible reset sequences to reset and classify devices.  This
   function is intended to be used for constructing -&gt;probe_reset
   callback by low level drivers.
   </para><para>

   Reset methods should follow the following rules.
   </para><para>

   - Return 0 on sucess, -errno on failure.
   - If classification is supported, fill classes[] with
   recognized class codes.
   - If classification is not supported, leave classes[] alone.
   - If verbose is non-zero, print error message on failure;
   otherwise, shut up.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -EINVAL if no reset method is avaliable, -ENODEV
   if classification fails, and any error code from reset
   methods.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-revalidate">ata_dev_revalidate</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_revalidate</refname>
 <refpurpose>
      Revalidate ATA device
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_dev_revalidate </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>int <parameter>post_reset</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port on which the device to revalidate resides
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     device to revalidate
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>post_reset</parameter></term>
   <listitem>
    <para>
     is this revalidation after reset?
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Re-read IDENTIFY page and make sure <parameter>dev</parameter> is still attached to
   the port.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, negative errno otherwise
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-qc-prep">ata_qc_prep</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_qc_prep</refname>
 <refpurpose>
      Prepare taskfile for submission
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_qc_prep </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     Metadata associated with taskfile to be prepared
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Prepare ATA taskfile for submission.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-sg-init-one">ata_sg_init_one</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_sg_init_one</refname>
 <refpurpose>
      Associate command with memory buffer
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_sg_init_one </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
   <paramdef>void * <parameter>buf</parameter></paramdef>
   <paramdef>unsigned int <parameter>buflen</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     Command to be associated
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>buf</parameter></term>
   <listitem>
    <para>
     Memory buffer
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>buflen</parameter></term>
   <listitem>
    <para>
     Length of memory buffer, in bytes.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Initialize the data-related elements of queued_cmd <parameter>qc</parameter>
   to point to a single memory buffer, <parameter>buf</parameter> of byte length <parameter>buflen</parameter>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-sg-init">ata_sg_init</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_sg_init</refname>
 <refpurpose>
      Associate command with scatter-gather table.
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_sg_init </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
   <paramdef>struct scatterlist * <parameter>sg</parameter></paramdef>
   <paramdef>unsigned int <parameter>n_elem</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     Command to be associated
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>sg</parameter></term>
   <listitem>
    <para>
     Scatter-gather table.
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>n_elem</parameter></term>
   <listitem>
    <para>
     Number of elements in s/g table.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Initialize the data-related elements of queued_cmd <parameter>qc</parameter>
   to point to a scatter-gather table <parameter>sg</parameter>, containing <parameter>n_elem</parameter>
   elements.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-eng-timeout">ata_eng_timeout</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_eng_timeout</refname>
 <refpurpose>
      Handle timeout of queued command
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_eng_timeout </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port on which timed-out command is active
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Some part of the kernel (currently, only the SCSI layer)
   has noticed that the active command on port <parameter>ap</parameter> has not
   completed after a specified length of time.  Handle this
   condition by disabling DMA (if necessary) and completing
   transactions, with error if necessary.
   </para><para>

   This also handles the case of the <quote>lost interrupt</quote>, where
   for some reason (possibly hardware bug, possibly driver bug)
   an interrupt was not delivered to the driver, even though the
   transaction completed successfully.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from SCSI layer (none, can sleep)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-qc-issue-prot">ata_qc_issue_prot</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_qc_issue_prot</refname>
 <refpurpose>
      issue taskfile to device in proto-dependent manner
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_qc_issue_prot </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     command to issue to device
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Using various libata functions and hooks, this function
   starts an ATA command.  ATA commands are grouped into
   classes called <quote>protocols</quote>, and issuing each type of protocol
   is slightly different.
   </para><para>

   May be used as the <function>qc_issue</function> entry in ata_port_operations.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Zero on success, AC_ERR_* mask on failure
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-host-intr">ata_host_intr</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_host_intr</refname>
 <refpurpose>
      Handle host interrupt for given (port, task)
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_host_intr </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port on which interrupt arrived (possibly...)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     Taskfile currently active in engine
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Handle host interrupt for given queued command.  Currently,
   only DMA interrupts are handled.  All other commands are
   handled via polling with interrupts disabled (nIEN bit).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   One if interrupt was handled, zero if not (shared irq).
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-interrupt">ata_interrupt</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_interrupt</refname>
 <refpurpose>
      Default ATA host interrupt handler
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>irqreturn_t <function>ata_interrupt </function></funcdef>
   <paramdef>int <parameter>irq</parameter></paramdef>
   <paramdef>void * <parameter>dev_instance</parameter></paramdef>
   <paramdef>struct pt_regs * <parameter>regs</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>irq</parameter></term>
   <listitem>
    <para>
     irq line (unused)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev_instance</parameter></term>
   <listitem>
    <para>
     pointer to our ata_host_set information structure
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>regs</parameter></term>
   <listitem>
    <para>
     unused
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Default interrupt handler for PCI IDE devices.  Calls
   <function>ata_host_intr</function> for each port that is not disabled.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Obtains host_set lock during operation.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   IRQ_NONE or IRQ_HANDLED.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-device-resume">ata_device_resume</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_device_resume</refname>
 <refpurpose>
      wakeup a previously suspended devices
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_device_resume </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port the device is connected to
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     the device to resume
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Kick the drive back into action, by sending it an idle immediate
   command and making sure its transfer mode matches between drive
   and host.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-device-suspend">ata_device_suspend</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_device_suspend</refname>
 <refpurpose>
      prepare a device for suspend
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_device_suspend </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>pm_message_t <parameter>state</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port the device is connected to
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     the device to suspend
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>state</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Flush the cache on the drive, if appropriate, then issue a
   standbynow command.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-start">ata_port_start</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_start</refname>
 <refpurpose>
      Set port up for dma.
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_port_start </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port to initialize
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Called just after data structures for each port are
   initialized.  Allocates space for PRD table.
   </para><para>

   May be used as the <function>port_start</function> entry in ata_port_operations.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-stop">ata_port_stop</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_stop</refname>
 <refpurpose>
      Undo <function>ata_port_start</function>
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_port_stop </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port to shut down
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Frees the PRD table.
   </para><para>

   May be used as the <function>port_stop</function> entry in ata_port_operations.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-device-add">ata_device_add</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_device_add</refname>
 <refpurpose>
      Register hardware device with ATA and SCSI layers
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_device_add </function></funcdef>
   <paramdef>const struct ata_probe_ent * <parameter>ent</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ent</parameter></term>
   <listitem>
    <para>
     Probe information describing hardware device to be registered
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function processes the information provided in the probe
   information struct <parameter>ent</parameter>, allocates the necessary ATA and SCSI
   host information structures, initializes them, and registers
   everything with requisite kernel subsystems.
   </para><para>

   This function requests irqs, probes the ATA bus, and probes
   the SCSI bus.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Number of ports registered.  Zero on error (no ports registered).
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-host-set-remove">ata_host_set_remove</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_host_set_remove</refname>
 <refpurpose>
      PCI layer callback for device removal
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_host_set_remove </function></funcdef>
   <paramdef>struct ata_host_set * <parameter>host_set</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>host_set</parameter></term>
   <listitem>
    <para>
     ATA host set that was removed
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Unregister all objects associated with this host set. Free those
   objects.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from calling layer (may sleep).
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-scsi-release">ata_scsi_release</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_scsi_release</refname>
 <refpurpose>
      SCSI layer callback hook for host unload
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_scsi_release </function></funcdef>
   <paramdef>struct Scsi_Host * <parameter>host</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>host</parameter></term>
   <listitem>
    <para>
     libata host to be unloaded
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Performs all duties necessary to shut down a libata port...
   Kill port kthread, disable port, and release resources.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from SCSI layer.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   One.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-std-ports">ata_std_ports</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_std_ports</refname>
 <refpurpose>
      initialize ioaddr with standard port offsets.
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_std_ports </function></funcdef>
   <paramdef>struct ata_ioports * <parameter>ioaddr</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ioaddr</parameter></term>
   <listitem>
    <para>
     IO address structure to be initialized
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Utility function which initializes data_addr, error_addr,
   feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
   device_addr, status_addr, and command_addr to standard offsets
   relative to cmd_addr.
   </para><para>

   Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-pci-remove-one">ata_pci_remove_one</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_pci_remove_one</refname>
 <refpurpose>
      PCI layer callback for device removal
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_pci_remove_one </function></funcdef>
   <paramdef>struct pci_dev * <parameter>pdev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>pdev</parameter></term>
   <listitem>
    <para>
     PCI device that was removed
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   PCI layer indicates to libata via this hook that
   hot-unplug or module unload event has occurred.
   Handle this by unregistering all objects associated
   with this PCI device.  Free those objects.  Then finally
   release PCI resources and disable device.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Inherited from PCI layer (may sleep).
</para>
</refsect1>
</refentry>

  </chapter>

  <chapter id="libataInt">
     <title>libata Core Internals</title>
<!-- drivers/scsi/libata-core.c -->
<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-rwcmd-protocol">ata_rwcmd_protocol</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_rwcmd_protocol</refname>
 <refpurpose>
   set taskfile r/w commands and protocol
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_rwcmd_protocol </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     command to examine and configure
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Examine the device configuration and tf-&gt;flags to calculate
   the proper read/write commands and protocol to use.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-pack-xfermask">ata_pack_xfermask</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_pack_xfermask</refname>
 <refpurpose>
      Pack pio, mwdma and udma masks into xfer_mask
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_pack_xfermask </function></funcdef>
   <paramdef>unsigned int <parameter>pio_mask</parameter></paramdef>
   <paramdef>unsigned int <parameter>mwdma_mask</parameter></paramdef>
   <paramdef>unsigned int <parameter>udma_mask</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>pio_mask</parameter></term>
   <listitem>
    <para>
     pio_mask
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>mwdma_mask</parameter></term>
   <listitem>
    <para>
     mwdma_mask
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>udma_mask</parameter></term>
   <listitem>
    <para>
     udma_mask
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Pack <parameter>pio_mask</parameter>, <parameter>mwdma_mask</parameter> and <parameter>udma_mask</parameter> into a single
   unsigned int xfer_mask.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Packed xfer_mask.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-unpack-xfermask">ata_unpack_xfermask</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_unpack_xfermask</refname>
 <refpurpose>
      Unpack xfer_mask into pio, mwdma and udma masks
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_unpack_xfermask </function></funcdef>
   <paramdef>unsigned int <parameter>xfer_mask</parameter></paramdef>
   <paramdef>unsigned int * <parameter>pio_mask</parameter></paramdef>
   <paramdef>unsigned int * <parameter>mwdma_mask</parameter></paramdef>
   <paramdef>unsigned int * <parameter>udma_mask</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>xfer_mask</parameter></term>
   <listitem>
    <para>
     xfer_mask to unpack
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>pio_mask</parameter></term>
   <listitem>
    <para>
     resulting pio_mask
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>mwdma_mask</parameter></term>
   <listitem>
    <para>
     resulting mwdma_mask
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>udma_mask</parameter></term>
   <listitem>
    <para>
     resulting udma_mask
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Unpack <parameter>xfer_mask</parameter> into <parameter>pio_mask</parameter>, <parameter>mwdma_mask</parameter> and <parameter>udma_mask</parameter>.
   Any NULL distination masks will be ignored.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-xfer-mask2mode">ata_xfer_mask2mode</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_xfer_mask2mode</refname>
 <refpurpose>
      Find matching XFER_* for the given xfer_mask
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>u8 <function>ata_xfer_mask2mode </function></funcdef>
   <paramdef>unsigned int <parameter>xfer_mask</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>xfer_mask</parameter></term>
   <listitem>
    <para>
     xfer_mask of interest
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Return matching XFER_* value for <parameter>xfer_mask</parameter>.  Only the highest
   bit of <parameter>xfer_mask</parameter> is considered.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Matching XFER_* value, 0 if no match found.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-xfer-mode2mask">ata_xfer_mode2mask</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_xfer_mode2mask</refname>
 <refpurpose>
      Find matching xfer_mask for XFER_*
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_xfer_mode2mask </function></funcdef>
   <paramdef>u8 <parameter>xfer_mode</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>xfer_mode</parameter></term>
   <listitem>
    <para>
     XFER_* of interest
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Return matching xfer_mask for <parameter>xfer_mode</parameter>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Matching xfer_mask, 0 if no match found.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-xfer-mode2shift">ata_xfer_mode2shift</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_xfer_mode2shift</refname>
 <refpurpose>
      Find matching xfer_shift for XFER_*
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_xfer_mode2shift </function></funcdef>
   <paramdef>unsigned int <parameter>xfer_mode</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>xfer_mode</parameter></term>
   <listitem>
    <para>
     XFER_* of interest
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Return matching xfer_shift for <parameter>xfer_mode</parameter>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Matching xfer_shift, -1 if no match found.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-mode-string">ata_mode_string</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_mode_string</refname>
 <refpurpose>
      convert xfer_mask to string
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>const char * <function>ata_mode_string </function></funcdef>
   <paramdef>unsigned int <parameter>xfer_mask</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>xfer_mask</parameter></term>
   <listitem>
    <para>
     mask of bits supported; only highest bit counts.
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Determine string which represents the highest speed
   (highest bit in <parameter>modemask</parameter>).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Constant C string representing highest speed listed in
   <parameter>mode_mask</parameter>, or the constant C string <quote>&lt;n/a&gt;</quote>.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-pio-devchk">ata_pio_devchk</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_pio_devchk</refname>
 <refpurpose>
      PATA device presence detection
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_pio_devchk </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     Device to examine (starting at zero)
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This technique was originally described in
   Hale Landis's ATADRVR (www.ata-atapi.com), and
   later found its way into the ATA/ATAPI spec.
   </para><para>

   Write a pattern to the ATA shadow registers,
   and if a device is present, it will respond by
   correctly storing and echoing back the
   ATA shadow register contents.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-mmio-devchk">ata_mmio_devchk</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_mmio_devchk</refname>
 <refpurpose>
      PATA device presence detection
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_mmio_devchk </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     Device to examine (starting at zero)
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This technique was originally described in
   Hale Landis's ATADRVR (www.ata-atapi.com), and
   later found its way into the ATA/ATAPI spec.
   </para><para>

   Write a pattern to the ATA shadow registers,
   and if a device is present, it will respond by
   correctly storing and echoing back the
   ATA shadow register contents.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-devchk">ata_devchk</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_devchk</refname>
 <refpurpose>
      PATA device presence detection
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_devchk </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     Device to examine (starting at zero)
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Dispatch ATA device presence detection, depending
   on whether we are using PIO or MMIO to talk to the
   ATA shadow registers.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-try-classify">ata_dev_try_classify</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_try_classify</refname>
 <refpurpose>
      Parse returned ATA device signature
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_dev_try_classify </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
   <paramdef>u8 * <parameter>r_err</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to examine
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     Device to examine (starting at zero)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>r_err</parameter></term>
   <listitem>
    <para>
     Value of error register on completion
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   After an event -- SRST, E.D.D., or SATA COMRESET -- occurs,
   an ATA/ATAPI-defined set of values is placed in the ATA
   shadow registers, indicating the results of device detection
   and diagnostics.
   </para><para>

   Select the ATA device, and read the values from the ATA shadow
   registers.  Then parse according to the Error register value,
   and the spec-defined values examined by <function>ata_dev_classify</function>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Device type - <constant>ATA_DEV_ATA</constant>, <constant>ATA_DEV_ATAPI</constant> or <constant>ATA_DEV_NONE</constant>.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-select">ata_dev_select</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_select</refname>
 <refpurpose>
      Select device 0/1 on ATA bus
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_dev_select </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>unsigned int <parameter>device</parameter></paramdef>
   <paramdef>unsigned int <parameter>wait</parameter></paramdef>
   <paramdef>unsigned int <parameter>can_sleep</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     ATA channel to manipulate
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>device</parameter></term>
   <listitem>
    <para>
     ATA device (numbered from zero) to select
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>wait</parameter></term>
   <listitem>
    <para>
     non-zero to wait for Status register BSY bit to clear
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>can_sleep</parameter></term>
   <listitem>
    <para>
     non-zero if context allows sleeping
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Use the method defined in the ATA specification to
   make either device 0, or device 1, active on the
   ATA channel.
   </para><para>

   This is a high-level version of <function>ata_std_dev_select</function>,
   which additionally provides the services of inserting
   the proper pauses and status polling, where needed.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dump-id">ata_dump_id</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dump_id</refname>
 <refpurpose>
      IDENTIFY DEVICE info debugging output
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_dump_id </function></funcdef>
   <paramdef>const u16 * <parameter>id</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>id</parameter></term>
   <listitem>
    <para>
     IDENTIFY DEVICE page to dump
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Dump selected 16-bit words from the given IDENTIFY DEVICE
   page.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   caller.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-id-xfermask">ata_id_xfermask</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_id_xfermask</refname>
 <refpurpose>
      Compute xfermask from the given IDENTIFY data
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_id_xfermask </function></funcdef>
   <paramdef>const u16 * <parameter>id</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>id</parameter></term>
   <listitem>
    <para>
     IDENTIFY data to compute xfer mask from
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Compute the xfermask for this device. This is not as trivial
   as it seems if we must consider early devices correctly.
</para>
</refsect1>
<refsect1>
<title>FIXME</title>
<para>
   pre IDE drive timing (do we care ?).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Computed xfermask
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-port-flush-task">ata_port_flush_task</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_port_flush_task</refname>
 <refpurpose>
      Flush port_task
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_port_flush_task </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     The ata_port to flush port_task for
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   After this function completes, port_task is guranteed not to
   be running or scheduled.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-exec-internal">ata_exec_internal</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_exec_internal</refname>
 <refpurpose>
      execute libata internal command
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned <function>ata_exec_internal </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>struct ata_taskfile * <parameter>tf</parameter></paramdef>
   <paramdef>int <parameter>dma_dir</parameter></paramdef>
   <paramdef>void * <parameter>buf</parameter></paramdef>
   <paramdef>unsigned int <parameter>buflen</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port to which the command is sent
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     Device to which the command is sent
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>tf</parameter></term>
   <listitem>
    <para>
     Taskfile registers for the command and the result
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dma_dir</parameter></term>
   <listitem>
    <para>
     Data tranfer direction of the command
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>buf</parameter></term>
   <listitem>
    <para>
     Data buffer of the command
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>buflen</parameter></term>
   <listitem>
    <para>
     Length of data buffer
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Executes libata internal command with timeout.  <parameter>tf</parameter> contains
   command on entry and result on return.  Timeout and error
   conditions are reported via return value.  No recovery action
   is taken after a command times out.  It's caller's duty to
   clean up after timeout.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.  Should be called with kernel context, might sleep.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-read-id">ata_dev_read_id</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_read_id</refname>
 <refpurpose>
      Read ID data from the specified device
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_dev_read_id </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>unsigned int * <parameter>p_class</parameter></paramdef>
   <paramdef>int <parameter>post_reset</parameter></paramdef>
   <paramdef>u16 ** <parameter>p_id</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port on which target device resides
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     target device
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>p_class</parameter></term>
   <listitem>
    <para>
     pointer to class of the target device (may be changed)
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>post_reset</parameter></term>
   <listitem>
    <para>
     is this read ID post-reset?
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>p_id</parameter></term>
   <listitem>
    <para>
     read IDENTIFY page (newly allocated)
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Read ID data from the specified device.  ATA_CMD_ID_ATA is
   performed on ATA devices and ATA_CMD_ID_ATAPI on ATAPI
   devices.  This function also issues ATA_CMD_INIT_DEV_PARAMS
   for pre-ATA4 drives.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -errno otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-configure">ata_dev_configure</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_configure</refname>
 <refpurpose>
      Configure the specified ATA/ATAPI device
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_dev_configure </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>int <parameter>print_info</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port on which target device resides
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     Target device to configure
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>print_info</parameter></term>
   <listitem>
    <para>
     Enable device info printout
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Configure <parameter>dev</parameter> according to <parameter>dev</parameter>-&gt;id.  Generic and low-level
   driver specific fixups are also applied.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, -errno otherwise
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-bus-probe">ata_bus_probe</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_bus_probe</refname>
 <refpurpose>
      Reset and probe ATA bus
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_bus_probe </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Bus to probe
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Master ATA bus probing function.  Initiates a hardware-dependent
   bus reset, then attempts to identify any devices found on
   the bus.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   Zero on success, non-zero on error.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-sata-print-link-status">sata_print_link_status</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>sata_print_link_status</refname>
 <refpurpose>
      Print SATA link status
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>sata_print_link_status </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     SATA port to printk link status about
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   This function prints link speed and status of a SATA link.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-set-mode">ata_set_mode</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_set_mode</refname>
 <refpurpose>
      Program timings and issue SET FEATURES - XFER
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_set_mode </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port on which timings will be programmed
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Set ATA device disk transfer mode (PIO3, UDMA6, etc.).
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-tf-to-host">ata_tf_to_host</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_tf_to_host</refname>
 <refpurpose>
      issue ATA taskfile to host controller
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_tf_to_host </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>const struct ata_taskfile * <parameter>tf</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port to which command is being issued
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>tf</parameter></term>
   <listitem>
    <para>
     ATA taskfile register set
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Issues ATA taskfile register set to ATA host controller,
   with proper synchronization with interrupt handler and
   other threads.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-same-device">ata_dev_same_device</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_same_device</refname>
 <refpurpose>
      Determine whether new ID matches configured device
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>int <function>ata_dev_same_device </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>unsigned int <parameter>new_class</parameter></paramdef>
   <paramdef>const u16 * <parameter>new_id</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     port on which the device to compare against resides
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     device to compare against
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>new_class</parameter></term>
   <listitem>
    <para>
     class of the new device
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>new_id</parameter></term>
   <listitem>
    <para>
     IDENTIFY page of the new device
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Compare <parameter>new_class</parameter> and <parameter>new_id</parameter> against <parameter>dev</parameter> and determine
   whether <parameter>dev</parameter> is the device indicated by <parameter>new_class</parameter> and
   <parameter>new_id</parameter>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   1 if <parameter>dev</parameter> matches <parameter>new_class</parameter> and <parameter>new_id</parameter>, 0 otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-xfermask">ata_dev_xfermask</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_xfermask</refname>
 <refpurpose>
      Compute supported xfermask of the given device
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_dev_xfermask </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port on which the device to compute xfermask for resides
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     Device to compute xfermask for
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Compute supported xfermask of <parameter>dev</parameter> and store it in
   dev-&gt;*_mask.  This function is responsible for applying all
   known limits including host controller limits, device
   blacklist, etc...
</para>
</refsect1>
<refsect1>
<title>FIXME</title>
<para>
   The current implementation limits all transfer modes to
   the fastest of the lowested device on the port.  This is not
   required on most controllers.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   None.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-set-xfermode">ata_dev_set_xfermode</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_set_xfermode</refname>
 <refpurpose>
      Issue SET FEATURES - XFER MODE command
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_dev_set_xfermode </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port associated with device <parameter>dev</parameter>
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     Device to which command will be sent
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Issue SET FEATURES - XFER MODE command to device <parameter>dev</parameter>
   on port <parameter>ap</parameter>.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   PCI/etc. bus probe sem.
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, AC_ERR_* mask otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-dev-init-params">ata_dev_init_params</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_dev_init_params</refname>
 <refpurpose>
      Issue INIT DEV PARAMS command
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>unsigned int <function>ata_dev_init_params </function></funcdef>
   <paramdef>struct ata_port * <parameter>ap</parameter></paramdef>
   <paramdef>struct ata_device * <parameter>dev</parameter></paramdef>
   <paramdef>u16 <parameter>heads</parameter></paramdef>
   <paramdef>u16 <parameter>sectors</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>ap</parameter></term>
   <listitem>
    <para>
     Port associated with device <parameter>dev</parameter>
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>dev</parameter></term>
   <listitem>
    <para>
     Device to which command will be sent
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>heads</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
  <varlistentry>
   <term><parameter>sectors</parameter></term>
   <listitem>
    <para>
     -- undescribed --
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   Kernel thread context (may sleep)
</para>
</refsect1>
<refsect1>
<title>RETURNS</title>
<para>
   0 on success, AC_ERR_* mask otherwise.
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-sg-clean">ata_sg_clean</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_sg_clean</refname>
 <refpurpose>
      Unmap DMA memory associated with command
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_sg_clean </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisdiv>
<refsect1>
 <title>Arguments</title>
 <variablelist>
  <varlistentry>
   <term><parameter>qc</parameter></term>
   <listitem>
    <para>
     Command containing DMA memory to be released
    </para>
   </listitem>
  </varlistentry>
 </variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>
   Unmap all mapped DMA memory associated with this command.
</para>
</refsect1>
<refsect1>
<title>LOCKING</title>
<para>
   spin_lock_irqsave(host_set lock)
</para>
</refsect1>
</refentry>

<refentry>
<refentryinfo>
 <title>LINUX</title>
 <productname>Kernel Hackers Manual</productname>
 <date>November 2007</date>
</refentryinfo>
<refmeta>
 <refentrytitle><phrase id="API-ata-fill-sg">ata_fill_sg</phrase></refentrytitle>
 <manvolnum>9</manvolnum>
</refmeta>
<refnamediv>
 <refname>ata_fill_sg</refname>
 <refpurpose>
      Fill PCI IDE PRD table
 </refpurpose>
</refnamediv>
<refsynopsisdiv>
 <title>Synopsis</title>
  <funcsynopsis><funcprototype>
   <funcdef>void <function>ata_fill_sg </function></funcdef>
   <paramdef>struct ata_queued_cmd * <parameter>qc</parameter></paramdef>
  </funcprototype></funcsynopsis>
</refsynopsisd