libata.tmpl 10.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?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>
J
Jeff Garzik 已提交
17
   <year>2003-2005</year>
L
Linus Torvalds 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   <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>

J
Jeff Garzik 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60
  <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>

L
Linus Torvalds 已提交
61 62
  <chapter id="libataDriverApi">
     <title>libata Driver API</title>
J
Jeff Garzik 已提交
63 64 65 66 67 68 69 70 71 72 73 74
     <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>
L
Linus Torvalds 已提交
75 76 77
     <sect1>
        <title>struct ata_port_operations</title>

J
Jeff Garzik 已提交
78
	<sect2><title>Disable ATA port</title>
L
Linus Torvalds 已提交
79 80 81 82 83 84 85 86 87 88
	<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).
	</para>

J
Jeff Garzik 已提交
89 90 91
	</sect2>

	<sect2><title>Post-IDENTIFY device configuration</title>
L
Linus Torvalds 已提交
92 93 94 95 96 97 98 99 100 101
	<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>

J
Jeff Garzik 已提交
102 103 104
	</sect2>

	<sect2><title>Set PIO/DMA mode</title>
L
Linus Torvalds 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
	<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 *ap);
	</programlisting>

	<para>
	Hooks called prior to the issue of SET FEATURES - XFER MODE
	command.  dev->pio_mode is guaranteed to be valid when
	->set_piomode() is called, and dev->dma_mode is guaranteed to be
	valid when ->set_dmamode() is called.  ->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>

J
Jeff Garzik 已提交
125 126 127
	</sect2>

	<sect2><title>Taskfile read/write</title>
L
Linus Torvalds 已提交
128 129 130 131 132 133 134 135 136 137 138 139
	<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.
	</para>

J
Jeff Garzik 已提交
140 141 142
	</sect2>

	<sect2><title>ATA command execute</title>
L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150 151
	<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.
	</para>

J
Jeff Garzik 已提交
152 153 154
	</sect2>

	<sect2><title>Per-cmd ATAPI DMA capabilities filter</title>
J
Jeff Garzik 已提交
155 156 157 158 159 160 161 162 163 164
	<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>

J
Jeff Garzik 已提交
165 166 167
	</sect2>

	<sect2><title>Read specific ATA shadow registers</title>
L
Linus Torvalds 已提交
168 169
	<programlisting>
u8   (*check_status)(struct ata_port *ap);
J
Jeff Garzik 已提交
170 171
u8   (*check_altstatus)(struct ata_port *ap);
u8   (*check_err)(struct ata_port *ap);
L
Linus Torvalds 已提交
172 173 174
	</programlisting>

	<para>
J
Jeff Garzik 已提交
175 176 177
	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.
L
Linus Torvalds 已提交
178 179
	</para>

J
Jeff Garzik 已提交
180 181 182
	</sect2>

	<sect2><title>Select ATA device on bus</title>
L
Linus Torvalds 已提交
183 184 185 186 187 188 189
	<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
J
Jeff Garzik 已提交
190 191
	available for use) on the ATA bus.  This generally has no
meaning on FIS-based devices.
L
Linus Torvalds 已提交
192 193
	</para>

J
Jeff Garzik 已提交
194 195 196
	</sect2>

	<sect2><title>Reset ATA bus</title>
L
Linus Torvalds 已提交
197 198 199 200 201 202 203 204 205 206 207 208
	<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.
	</para>

J
Jeff Garzik 已提交
209 210 211
	</sect2>

	<sect2><title>Control PCI IDE BMDMA engine</title>
L
Linus Torvalds 已提交
212 213 214
	<programlisting>
void (*bmdma_setup) (struct ata_queued_cmd *qc);
void (*bmdma_start) (struct ata_queued_cmd *qc);
J
Jeff Garzik 已提交
215 216
void (*bmdma_stop) (struct ata_port *ap);
u8   (*bmdma_status) (struct ata_port *ap);
L
Linus Torvalds 已提交
217 218 219
	</programlisting>

	<para>
J
Jeff Garzik 已提交
220 221 222 223 224 225 226 227 228
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.
L
Linus Torvalds 已提交
229 230
	</para>

J
Jeff Garzik 已提交
231 232 233
	</sect2>

	<sect2><title>High-level taskfile hooks</title>
L
Linus Torvalds 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
	<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
J
Jeff Garzik 已提交
251
	dispatch.  More advanced drivers implement their own ->qc_issue.
L
Linus Torvalds 已提交
252 253
	</para>

J
Jeff Garzik 已提交
254 255 256
	</sect2>

	<sect2><title>Timeout (error) handling</title>
L
Linus Torvalds 已提交
257 258 259 260 261
	<programlisting>
void (*eng_timeout) (struct ata_port *ap);
	</programlisting>

	<para>
J
Jeff Garzik 已提交
262 263 264 265
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().
L
Linus Torvalds 已提交
266 267
	</para>

J
Jeff Garzik 已提交
268 269 270
	</sect2>

	<sect2><title>Hardware interrupt handling</title>
L
Linus Torvalds 已提交
271 272 273 274 275 276 277 278 279 280 281 282
	<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>

J
Jeff Garzik 已提交
283 284 285
	</sect2>

	<sect2><title>SATA phy read/write</title>
L
Linus Torvalds 已提交
286 287 288 289 290 291 292 293 294 295 296
	<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.
	</para>

J
Jeff Garzik 已提交
297 298 299
	</sect2>

	<sect2><title>Init and shutdown</title>
L
Linus Torvalds 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
	<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.  
	</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.
	</para>
J
Jeff Garzik 已提交
317 318 319 320 321
	<para>
	->host_stop() is called after all ->port_stop() calls
have completed.  The hook must finalize hardware shutdown, release DMA
and other resources, etc.
	</para>
L
Linus Torvalds 已提交
322

J
Jeff Garzik 已提交
323 324
	</sect2>

L
Linus Torvalds 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
     </sect1>
  </chapter>

  <chapter id="libataExt">
     <title>libata Library</title>
!Edrivers/scsi/libata-core.c
  </chapter>

  <chapter id="libataInt">
     <title>libata Core Internals</title>
!Idrivers/scsi/libata-core.c
  </chapter>

  <chapter id="libataScsiInt">
     <title>libata SCSI translation/emulation</title>
!Edrivers/scsi/libata-scsi.c
!Idrivers/scsi/libata-scsi.c
  </chapter>

  <chapter id="PiixInt">
     <title>ata_piix Internals</title>
!Idrivers/scsi/ata_piix.c
  </chapter>

  <chapter id="SILInt">
     <title>sata_sil Internals</title>
!Idrivers/scsi/sata_sil.c
  </chapter>

J
Jeff Garzik 已提交
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
  <chapter id="libataThanks">
     <title>Thanks</title>
  <para>
  The bulk of the ATA knowledge comes thanks to long conversations with
  Andre Hedrick (www.linux-ide.org), and long hours pondering the ATA
  and SCSI specifications.
  </para>
  <para>
  Thanks to Alan Cox for pointing out similarities 
  between SATA and SCSI, and in general for motivation to hack on
  libata.
  </para>
  <para>
  libata's device detection
  method, ata_pio_devchk, and in general all the early probing was
  based on extensive study of Hale Landis's probe/reset code in his
  ATADRVR driver (www.ata-atapi.com).
  </para>
  </chapter>

L
Linus Torvalds 已提交
374
</book>