···1414 </authorgroup>15151616 <copyright>1717- <year>2003</year>1717+ <year>2003-2005</year>1818 <holder>Jeff Garzik</holder>1919 </copyright>2020···44444545<toc></toc>46464747- <chapter id="libataThanks">4848- <title>Thanks</title>4747+ <chapter id="libataIntroduction">4848+ <title>Introduction</title>4949 <para>5050- The bulk of the ATA knowledge comes thanks to long conversations with5151- Andre Hedrick (www.linux-ide.org).5050+ libATA is a library used inside the Linux kernel to support ATA host5151+ controllers and devices. libATA provides an ATA driver API, class5252+ transports for ATA and ATAPI devices, and SCSI<->ATA translation5353+ for ATA devices according to the T10 SAT specification.5254 </para>5355 <para>5454- Thanks to Alan Cox for pointing out similarities 5555- between SATA and SCSI, and in general for motivation to hack on5656- libata.5757- </para>5858- <para>5959- libata's device detection6060- method, ata_pio_devchk, and in general all the early probing was6161- based on extensive study of Hale Landis's probe/reset code in his6262- ATADRVR driver (www.ata-atapi.com).5656+ This Guide documents the libATA driver API, library functions, library5757+ internals, and a couple sample ATA low-level drivers.6358 </para>6459 </chapter>65606661 <chapter id="libataDriverApi">6762 <title>libata Driver API</title>6363+ <para>6464+ struct ata_port_operations is defined for every low-level libata6565+ hardware driver, and it controls how the low-level driver6666+ interfaces with the ATA and SCSI layers.6767+ </para>6868+ <para>6969+ FIS-based drivers will hook into the system with ->qc_prep() and7070+ ->qc_issue() high-level hooks. Hardware which behaves in a manner7171+ similar to PCI IDE hardware may utilize several generic helpers,7272+ defining at a bare minimum the bus I/O addresses of the ATA shadow7373+ register blocks.7474+ </para>6875 <sect1>6976 <title>struct ata_port_operations</title>70777878+ <sect2><title>Disable ATA port</title>7179 <programlisting>7280void (*port_disable) (struct ata_port *);7381 </programlisting>···8678 unplug).8779 </para>88808181+ </sect2>8282+8383+ <sect2><title>Post-IDENTIFY device configuration</title>8984 <programlisting>9085void (*dev_config) (struct ata_port *, struct ata_device *);9186 </programlisting>···9988 issue of SET FEATURES - XFER MODE, and prior to operation.10089 </para>101909191+ </sect2>9292+9393+ <sect2><title>Set PIO/DMA mode</title>10294 <programlisting>10395void (*set_piomode) (struct ata_port *, struct ata_device *);10496void (*set_dmamode) (struct ata_port *, struct ata_device *);···122108 ->set_dma_mode() is only called if DMA is possible.123109 </para>124110111111+ </sect2>112112+113113+ <sect2><title>Taskfile read/write</title>125114 <programlisting>126115void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf);127116void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);···137120 taskfile register values.138121 </para>139122123123+ </sect2>124124+125125+ <sect2><title>ATA command execute</title>140126 <programlisting>141127void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf);142128 </programlisting>···149129 ->tf_load(), to be initiated in hardware.150130 </para>151131132132+ </sect2>133133+134134+ <sect2><title>Per-cmd ATAPI DMA capabilities filter</title>152135 <programlisting>153153-u8 (*check_status)(struct ata_port *ap);154154-void (*dev_select)(struct ata_port *ap, unsigned int device);136136+int (*check_atapi_dma) (struct ata_queued_cmd *qc);155137 </programlisting>156138157139 <para>158158- Reads the Status ATA shadow register from hardware. On some159159- hardware, this has the side effect of clearing the interrupt160160- condition.140140+Allow low-level driver to filter ATA PACKET commands, returning a status141141+indicating whether or not it is OK to use DMA for the supplied PACKET142142+command.161143 </para>162144145145+ </sect2>146146+147147+ <sect2><title>Read specific ATA shadow registers</title>148148+ <programlisting>149149+u8 (*check_status)(struct ata_port *ap);150150+u8 (*check_altstatus)(struct ata_port *ap);151151+u8 (*check_err)(struct ata_port *ap);152152+ </programlisting>153153+154154+ <para>155155+ Reads the Status/AltStatus/Error ATA shadow register from156156+ hardware. On some hardware, reading the Status register has157157+ the side effect of clearing the interrupt condition.158158+ </para>159159+160160+ </sect2>161161+162162+ <sect2><title>Select ATA device on bus</title>163163 <programlisting>164164void (*dev_select)(struct ata_port *ap, unsigned int device);165165 </programlisting>···187147 <para>188148 Issues the low-level hardware command(s) that causes one of N189149 hardware devices to be considered 'selected' (active and190190- available for use) on the ATA bus.150150+ available for use) on the ATA bus. This generally has no151151+meaning on FIS-based devices.191152 </para>192153154154+ </sect2>155155+156156+ <sect2><title>Reset ATA bus</title>193157 <programlisting>194158void (*phy_reset) (struct ata_port *ap);195159 </programlisting>···206162 functions ata_bus_reset() or sata_phy_reset() for this hook.207163 </para>208164165165+ </sect2>166166+167167+ <sect2><title>Control PCI IDE BMDMA engine</title>209168 <programlisting>210169void (*bmdma_setup) (struct ata_queued_cmd *qc);211170void (*bmdma_start) (struct ata_queued_cmd *qc);171171+void (*bmdma_stop) (struct ata_port *ap);172172+u8 (*bmdma_status) (struct ata_port *ap);212173 </programlisting>213174214175 <para>215215- When setting up an IDE BMDMA transaction, these hooks arm216216- (->bmdma_setup) and fire (->bmdma_start) the hardware's DMA217217- engine.176176+When setting up an IDE BMDMA transaction, these hooks arm177177+(->bmdma_setup), fire (->bmdma_start), and halt (->bmdma_stop)178178+the hardware's DMA engine. ->bmdma_status is used to read the standard179179+PCI IDE DMA Status register.218180 </para>219181182182+ <para>183183+These hooks are typically either no-ops, or simply not implemented, in184184+FIS-based drivers.185185+ </para>186186+187187+ </sect2>188188+189189+ <sect2><title>High-level taskfile hooks</title>220190 <programlisting>221191void (*qc_prep) (struct ata_queued_cmd *qc);222192int (*qc_issue) (struct ata_queued_cmd *qc);···248190 ->qc_issue is used to make a command active, once the hardware249191 and S/G tables have been prepared. IDE BMDMA drivers use the250192 helper function ata_qc_issue_prot() for taskfile protocol-based251251- dispatch. More advanced drivers roll their own ->qc_issue252252- implementation, using this as the "issue new ATA command to253253- hardware" hook.193193+ dispatch. More advanced drivers implement their own ->qc_issue.254194 </para>255195196196+ </sect2>197197+198198+ <sect2><title>Timeout (error) handling</title>256199 <programlisting>257200void (*eng_timeout) (struct ata_port *ap);258201 </programlisting>259202260203 <para>261261- This is a high level error handling function, called from the262262- error handling thread, when a command times out.204204+This is a high level error handling function, called from the205205+error handling thread, when a command times out. Most newer206206+hardware will implement its own error handling code here. IDE BMDMA207207+drivers may use the helper function ata_eng_timeout().263208 </para>264209210210+ </sect2>211211+212212+ <sect2><title>Hardware interrupt handling</title>265213 <programlisting>266214irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);267215void (*irq_clear) (struct ata_port *);···280216 is quiet.281217 </para>282218219219+ </sect2>220220+221221+ <sect2><title>SATA phy read/write</title>283222 <programlisting>284223u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg);285224void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,···294227 if ->phy_reset hook called the sata_phy_reset() helper function.295228 </para>296229230230+ </sect2>231231+232232+ <sect2><title>Init and shutdown</title>297233 <programlisting>298234int (*port_start) (struct ata_port *ap);299235void (*port_stop) (struct ata_port *ap);···310240 tasks. 311241 </para>312242 <para>313313- ->host_stop() is called when the rmmod or hot unplug process314314- begins. The hook must stop all hardware interrupts, DMA315315- engines, etc.316316- </para>317317- <para>318243 ->port_stop() is called after ->host_stop(). It's sole function319244 is to release DMA/memory resources, now that they are no longer320245 actively being used.321246 </para>247247+ <para>248248+ ->host_stop() is called after all ->port_stop() calls249249+have completed. The hook must finalize hardware shutdown, release DMA250250+and other resources, etc.251251+ </para>252252+253253+ </sect2>322254323255 </sect1>324256 </chapter>···349277 <chapter id="SILInt">350278 <title>sata_sil Internals</title>351279!Idrivers/scsi/sata_sil.c280280+ </chapter>281281+282282+ <chapter id="libataThanks">283283+ <title>Thanks</title>284284+ <para>285285+ The bulk of the ATA knowledge comes thanks to long conversations with286286+ Andre Hedrick (www.linux-ide.org), and long hours pondering the ATA287287+ and SCSI specifications.288288+ </para>289289+ <para>290290+ Thanks to Alan Cox for pointing out similarities 291291+ between SATA and SCSI, and in general for motivation to hack on292292+ libata.293293+ </para>294294+ <para>295295+ libata's device detection296296+ method, ata_pio_devchk, and in general all the early probing was297297+ based on extensive study of Hale Landis's probe/reset code in his298298+ ATADRVR driver (www.ata-atapi.com).299299+ </para>352300 </chapter>353301354302</book>
···186186 ata_wait_idle(ap);187187}188188189189+190190+/**191191+ * ata_tf_load - send taskfile registers to host controller192192+ * @ap: Port to which output is sent193193+ * @tf: ATA taskfile register set194194+ *195195+ * Outputs ATA taskfile to standard ATA host controller using MMIO196196+ * or PIO as indicated by the ATA_FLAG_MMIO flag.197197+ * Writes the control, feature, nsect, lbal, lbam, and lbah registers.198198+ * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,199199+ * hob_lbal, hob_lbam, and hob_lbah.200200+ *201201+ * This function waits for idle (!BUSY and !DRQ) after writing202202+ * registers. If the control register has a new value, this203203+ * function also waits for idle after writing control and before204204+ * writing the remaining registers.205205+ *206206+ * May be used as the tf_load() entry in ata_port_operations.207207+ *208208+ * LOCKING:209209+ * Inherited from caller.210210+ */189211void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf)190212{191213 if (ap->flags & ATA_FLAG_MMIO)···217195}218196219197/**220220- * ata_exec_command - issue ATA command to host controller198198+ * ata_exec_command_pio - issue ATA command to host controller221199 * @ap: port to which command is being issued222200 * @tf: ATA taskfile register set223201 *224224- * Issues PIO/MMIO write to ATA command register, with proper202202+ * Issues PIO write to ATA command register, with proper225203 * synchronization with interrupt handler / other threads.226204 *227205 * LOCKING:···257235 ata_pause(ap);258236}259237238238+239239+/**240240+ * ata_exec_command - issue ATA command to host controller241241+ * @ap: port to which command is being issued242242+ * @tf: ATA taskfile register set243243+ *244244+ * Issues PIO/MMIO write to ATA command register, with proper245245+ * synchronization with interrupt handler / other threads.246246+ *247247+ * LOCKING:248248+ * spin_lock_irqsave(host_set lock)249249+ */260250void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf)261251{262252 if (ap->flags & ATA_FLAG_MMIO)···339305}340306341307/**342342- * ata_tf_read - input device's ATA taskfile shadow registers308308+ * ata_tf_read_pio - input device's ATA taskfile shadow registers343309 * @ap: Port from which input is read344310 * @tf: ATA taskfile register set for storing input345311 *···402368 }403369}404370371371+372372+/**373373+ * ata_tf_read - input device's ATA taskfile shadow registers374374+ * @ap: Port from which input is read375375+ * @tf: ATA taskfile register set for storing input376376+ *377377+ * Reads ATA taskfile registers for currently-selected device378378+ * into @tf.379379+ *380380+ * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48381381+ * is set, also reads the hob registers.382382+ *383383+ * May be used as the tf_read() entry in ata_port_operations.384384+ *385385+ * LOCKING:386386+ * Inherited from caller.387387+ */405388void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)406389{407390 if (ap->flags & ATA_FLAG_MMIO)···432381 * @ap: port where the device is433382 *434383 * Reads ATA taskfile status register for currently-selected device435435- * and return it's value. This also clears pending interrupts384384+ * and return its value. This also clears pending interrupts436385 * from this device437386 *438387 * LOCKING:···448397 * @ap: port where the device is449398 *450399 * Reads ATA taskfile status register for currently-selected device451451- * via MMIO and return it's value. This also clears pending interrupts400400+ * via MMIO and return its value. This also clears pending interrupts452401 * from this device453402 *454403 * LOCKING:···459408 return readb((void __iomem *) ap->ioaddr.status_addr);460409}461410411411+412412+/**413413+ * ata_check_status - Read device status reg & clear interrupt414414+ * @ap: port where the device is415415+ *416416+ * Reads ATA taskfile status register for currently-selected device417417+ * and return its value. This also clears pending interrupts418418+ * from this device419419+ *420420+ * May be used as the check_status() entry in ata_port_operations.421421+ *422422+ * LOCKING:423423+ * Inherited from caller.424424+ */462425u8 ata_check_status(struct ata_port *ap)463426{464427 if (ap->flags & ATA_FLAG_MMIO)···480415 return ata_check_status_pio(ap);481416}482417418418+419419+/**420420+ * ata_altstatus - Read device alternate status reg421421+ * @ap: port where the device is422422+ *423423+ * Reads ATA taskfile alternate status register for424424+ * currently-selected device and return its value.425425+ *426426+ * Note: may NOT be used as the check_altstatus() entry in427427+ * ata_port_operations.428428+ *429429+ * LOCKING:430430+ * Inherited from caller.431431+ */483432u8 ata_altstatus(struct ata_port *ap)484433{485434 if (ap->ops->check_altstatus)···504425 return inb(ap->ioaddr.altstatus_addr);505426}506427428428+429429+/**430430+ * ata_chk_err - Read device error reg431431+ * @ap: port where the device is432432+ *433433+ * Reads ATA taskfile error register for434434+ * currently-selected device and return its value.435435+ *436436+ * Note: may NOT be used as the check_err() entry in437437+ * ata_port_operations.438438+ *439439+ * LOCKING:440440+ * Inherited from caller.441441+ */507442u8 ata_chk_err(struct ata_port *ap)508443{509444 if (ap->ops->check_err)···966873 }967874}968875876876+877877+/**878878+ * ata_noop_dev_select - Select device 0/1 on ATA bus879879+ * @ap: ATA channel to manipulate880880+ * @device: ATA device (numbered from zero) to select881881+ *882882+ * This function performs no actual function.883883+ *884884+ * May be used as the dev_select() entry in ata_port_operations.885885+ *886886+ * LOCKING:887887+ * caller.888888+ */969889void ata_noop_dev_select (struct ata_port *ap, unsigned int device)970890{971891}892892+972893973894/**974895 * ata_std_dev_select - Select device 0/1 on ATA bus···991884 *992885 * Use the method defined in the ATA specification to993886 * make either device 0, or device 1, active on the994994- * ATA channel.887887+ * ATA channel. Works with both PIO and MMIO.888888+ *889889+ * May be used as the dev_select() entry in ata_port_operations.995890 *996891 * LOCKING:997892 * caller.···12991190 * ata_bus_probe - Reset and probe ATA bus13001191 * @ap: Bus to probe13011192 *11931193+ * Master ATA bus probing function. Initiates a hardware-dependent11941194+ * bus reset, then attempts to identify any devices found on11951195+ * the bus.11961196+ *13021197 * LOCKING:11981198+ * PCI/etc. bus probe sem.13031199 *13041200 * RETURNS:13051201 * Zero on success, non-zero on error.···13431229}1344123013451231/**13461346- * ata_port_probe -13471347- * @ap:12321232+ * ata_port_probe - Mark port as enabled12331233+ * @ap: Port for which we indicate enablement13481234 *13491349- * LOCKING:12351235+ * Modify @ap data structure such that the system12361236+ * thinks that the entire port is enabled.12371237+ *12381238+ * LOCKING: host_set lock, or some other form of12391239+ * serialization.13501240 */1351124113521242void ata_port_probe(struct ata_port *ap)···13591241}1360124213611243/**13621362- * __sata_phy_reset -13631363- * @ap:12441244+ * __sata_phy_reset - Wake/reset a low-level SATA PHY12451245+ * @ap: SATA port associated with target SATA PHY.12461246+ *12471247+ * This function issues commands to standard SATA Sxxx12481248+ * PHY registers, to wake up the phy (and device), and12491249+ * clear any reset condition.13641250 *13651251 * LOCKING:12521252+ * PCI/etc. bus probe sem.13661253 *13671254 */13681255void __sata_phy_reset(struct ata_port *ap)···14121289}1413129014141291/**14151415- * __sata_phy_reset -14161416- * @ap:12921292+ * sata_phy_reset - Reset SATA bus.12931293+ * @ap: SATA port associated with target SATA PHY.12941294+ *12951295+ * This function resets the SATA bus, and then probes12961296+ * the bus for devices.14171297 *14181298 * LOCKING:12991299+ * PCI/etc. bus probe sem.14191300 *14201301 */14211302void sata_phy_reset(struct ata_port *ap)···14311304}1432130514331306/**14341434- * ata_port_disable -14351435- * @ap:13071307+ * ata_port_disable - Disable port.13081308+ * @ap: Port to be disabled.14361309 *14371437- * LOCKING:13101310+ * Modify @ap data structure such that the system13111311+ * thinks that the entire port is disabled, and should13121312+ * never attempt to probe or communicate with devices13131313+ * on this port.13141314+ *13151315+ * LOCKING: host_set lock, or some other form of13161316+ * serialization.14381317 */1439131814401319void ata_port_disable(struct ata_port *ap)···15491416 * ata_set_mode - Program timings and issue SET FEATURES - XFER15501417 * @ap: port on which timings will be programmed15511418 *14191419+ * Set ATA device disk transfer mode (PIO3, UDMA6, etc.).14201420+ *15521421 * LOCKING:14221422+ * PCI/etc. bus probe sem.15531423 *15541424 */15551425static void ata_set_mode(struct ata_port *ap)···16031467 * @tmout_pat: impatience timeout16041468 * @tmout: overall timeout16051469 *16061606- * LOCKING:14701470+ * Sleep until ATA Status register bit BSY clears,14711471+ * or a timeout occurs.14721472+ *14731473+ * LOCKING: None.16071474 *16081475 */16091476···16921553}1693155416941555/**16951695- * ata_bus_edd -16961696- * @ap:15561556+ * ata_bus_edd - Issue EXECUTE DEVICE DIAGNOSTIC command.15571557+ * @ap: Port to reset and probe15581558+ *15591559+ * Use the EXECUTE DEVICE DIAGNOSTIC command to reset and15601560+ * probe the bus. Not often used these days.16971561 *16981562 * LOCKING:15631563+ * PCI/etc. bus probe sem.16991564 *17001565 */17011566···17761633 * the device is ATA or ATAPI.17771634 *17781635 * LOCKING:17791779- * Inherited from caller. Some functions called by this function17801780- * obtain the host_set lock.16361636+ * PCI/etc. bus probe sem.16371637+ * Obtains host_set lock.17811638 *17821639 * SIDE EFFECTS:17831640 * Sets ATA_FLAG_PORT_DISABLED if bus reset fails.···20191876 * @xfer_mode_out: (output) SET FEATURES - XFER MODE code20201877 * @xfer_shift_out: (output) bit shift that selects this mode20211878 *18791879+ * Based on host and device capabilities, determine the18801880+ * maximum transfer mode that is amenable to all.18811881+ *20221882 * LOCKING:18831883+ * PCI/etc. bus probe sem.20231884 *20241885 * RETURNS:20251886 * Zero on success, negative on error.···20561909 * @ap: Port associated with device @dev20571910 * @dev: Device to which command will be sent20581911 *19121912+ * Issue SET FEATURES - XFER MODE command to device @dev19131913+ * on port @ap.19141914+ *20591915 * LOCKING:19161916+ * PCI/etc. bus probe sem.20601917 */2061191820621919static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev)···20981947}2099194821001949/**21012101- * ata_sg_clean -21022102- * @qc:19501950+ * ata_sg_clean - Unmap DMA memory associated with command19511951+ * @qc: Command containing DMA memory to be released19521952+ *19531953+ * Unmap all mapped DMA memory associated with this command.21031954 *21041955 * LOCKING:19561956+ * spin_lock_irqsave(host_set lock)21051957 */2106195821071959static void ata_sg_clean(struct ata_queued_cmd *qc)···21351981 * ata_fill_sg - Fill PCI IDE PRD table21361982 * @qc: Metadata associated with taskfile to be transferred21371983 *19841984+ * Fill PCI IDE PRD (scatter-gather) table with segments19851985+ * associated with the current disk command.19861986+ *21381987 * LOCKING:19881988+ * spin_lock_irqsave(host_set lock)21391989 *21401990 */21411991static void ata_fill_sg(struct ata_queued_cmd *qc)···21862028 * ata_check_atapi_dma - Check whether ATAPI DMA can be supported21872029 * @qc: Metadata associated with taskfile to check21882030 *20312031+ * Allow low-level driver to filter ATA PACKET commands, returning20322032+ * a status indicating whether or not it is OK to use DMA for the20332033+ * supplied PACKET command.20342034+ *21892035 * LOCKING:20362036+ * spin_lock_irqsave(host_set lock)20372037+ *21902038 * RETURNS: 0 when ATAPI DMA can be used21912039 * nonzero otherwise21922040 */···22102046 * ata_qc_prep - Prepare taskfile for submission22112047 * @qc: Metadata associated with taskfile to be prepared22122048 *20492049+ * Prepare ATA taskfile for submission.20502050+ *22132051 * LOCKING:22142052 * spin_lock_irqsave(host_set lock)22152053 */···22232057 ata_fill_sg(qc);22242058}2225205920602060+/**20612061+ * ata_sg_init_one - Associate command with memory buffer20622062+ * @qc: Command to be associated20632063+ * @buf: Memory buffer20642064+ * @buflen: Length of memory buffer, in bytes.20652065+ *20662066+ * Initialize the data-related elements of queued_cmd @qc20672067+ * to point to a single memory buffer, @buf of byte length @buflen.20682068+ *20692069+ * LOCKING:20702070+ * spin_lock_irqsave(host_set lock)20712071+ */20722072+20732073+20742074+20752075+/**20762076+ * ata_sg_init_one - Prepare a one-entry scatter-gather list.20772077+ * @qc: Queued command20782078+ * @buf: transfer buffer20792079+ * @buflen: length of buf20802080+ *20812081+ * Builds a single-entry scatter-gather list to initiate a20822082+ * transfer utilizing the specified buffer.20832083+ *20842084+ * LOCKING:20852085+ */22262086void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)22272087{22282088 struct scatterlist *sg;···22662074 sg->length = buflen;22672075}2268207620772077+/**20782078+ * ata_sg_init - Associate command with scatter-gather table.20792079+ * @qc: Command to be associated20802080+ * @sg: Scatter-gather table.20812081+ * @n_elem: Number of elements in s/g table.20822082+ *20832083+ * Initialize the data-related elements of queued_cmd @qc20842084+ * to point to a scatter-gather table @sg, containing @n_elem20852085+ * elements.20862086+ *20872087+ * LOCKING:20882088+ * spin_lock_irqsave(host_set lock)20892089+ */20902090+20912091+20922092+/**20932093+ * ata_sg_init - Assign a scatter gather list to a queued command20942094+ * @qc: Queued command20952095+ * @sg: Scatter-gather list20962096+ * @n_elem: length of sg list20972097+ *20982098+ * Attaches a scatter-gather list to a queued command.20992099+ *21002100+ * LOCKING:21012101+ */21022102+22692103void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,22702104 unsigned int n_elem)22712105{···23012083}2302208423032085/**23042304- * ata_sg_setup_one -23052305- * @qc:20862086+ * ata_sg_setup_one - DMA-map the memory buffer associated with a command.20872087+ * @qc: Command with memory buffer to be mapped.20882088+ *20892089+ * DMA-map the memory buffer associated with queued_cmd @qc.23062090 *23072091 * LOCKING:23082092 * spin_lock_irqsave(host_set lock)23092093 *23102094 * RETURNS:23112311- *20952095+ * Zero on success, negative on error.23122096 */2313209723142098static int ata_sg_setup_one(struct ata_queued_cmd *qc)···23352115}2336211623372117/**23382338- * ata_sg_setup -23392339- * @qc:21182118+ * ata_sg_setup - DMA-map the scatter-gather table associated with a command.21192119+ * @qc: Command with scatter-gather table to be mapped.21202120+ *21212121+ * DMA-map the scatter-gather table associated with queued_cmd @qc.23402122 *23412123 * LOCKING:23422124 * spin_lock_irqsave(host_set lock)23432125 *23442126 * RETURNS:21272127+ * Zero on success, negative on error.23452128 *23462129 */23472130···23742151 * @ap:23752152 *23762153 * LOCKING:21542154+ * None. (executing in kernel thread context)23772155 *23782156 * RETURNS:23792157 *···24222198 * @ap:24232199 *24242200 * LOCKING:22012201+ * None. (executing in kernel thread context)24252202 */2426220324272204static void ata_pio_complete (struct ata_port *ap)···24652240 ata_qc_complete(qc, drv_stat);24662241}2467224222432243+22442244+/**22452245+ * swap_buf_le16 -22462246+ * @buf: Buffer to swap22472247+ * @buf_words: Number of 16-bit words in buffer.22482248+ *22492249+ * Swap halves of 16-bit words if needed to convert from22502250+ * little-endian byte order to native cpu byte order, or22512251+ * vice-versa.22522252+ *22532253+ * LOCKING:22542254+ */24682255void swap_buf_le16(u16 *buf, unsigned int buf_words)24692256{24702257#ifdef __BIG_ENDIAN···26522415 * @ap:26532416 *26542417 * LOCKING:24182418+ * None. (executing in kernel thread context)26552419 */2656242026572421static void ata_pio_block(struct ata_port *ap)···28212583 * transaction completed successfully.28222584 *28232585 * LOCKING:25862586+ * Inherited from SCSI layer (none, can sleep)28242587 */2825258828262589static void ata_qc_timeout(struct ata_queued_cmd *qc)···29312692 * @dev: Device from whom we request an available command structure29322693 *29332694 * LOCKING:26952695+ * None.29342696 */2935269729362698static struct ata_queued_cmd *ata_qc_new(struct ata_port *ap)···29572717 * @dev: Device from whom we request an available command structure29582718 *29592719 * LOCKING:27202720+ * None.29602721 */2961272229622723struct ata_queued_cmd *ata_qc_new_init(struct ata_port *ap,···30222781 * in case something prevents using it.30232782 *30242783 * LOCKING:27842784+ * spin_lock_irqsave(host_set lock)30252785 *30262786 */30272787void ata_qc_free(struct ata_queued_cmd *qc)···30362794/**30372795 * ata_qc_complete - Complete an active ATA command30382796 * @qc: Command to complete30393039- * @drv_stat: ATA status register contents27972797+ * @drv_stat: ATA Status register contents27982798+ *27992799+ * Indicate to the mid and upper layers that an ATA28002800+ * command has completed, with either an ok or not-ok status.30402801 *30412802 * LOCKING:28032803+ * spin_lock_irqsave(host_set lock)30422804 *30432805 */30442806···31382892 return -1;31392893}3140289428952895+31412896/**31422897 * ata_qc_issue_prot - issue taskfile to device in proto-dependent manner31432898 * @qc: command to issue to device···31472900 * starts an ATA command. ATA commands are grouped into31482901 * classes called "protocols", and issuing each type of protocol31492902 * is slightly different.29032903+ *29042904+ * May be used as the qc_issue() entry in ata_port_operations.31502905 *31512906 * LOCKING:31522907 * spin_lock_irqsave(host_set lock)···32072958}3208295932092960/**32103210- * ata_bmdma_setup - Set up PCI IDE BMDMA transaction29612961+ * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction32112962 * @qc: Info associated with this ATA transaction.32122963 *32132964 * LOCKING:···33143065 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);33153066}3316306730683068+30693069+/**30703070+ * ata_bmdma_start - Start a PCI IDE BMDMA transaction30713071+ * @qc: Info associated with this ATA transaction.30723072+ *30733073+ * Writes the ATA_DMA_START flag to the DMA command register.30743074+ *30753075+ * May be used as the bmdma_start() entry in ata_port_operations.30763076+ *30773077+ * LOCKING:30783078+ * spin_lock_irqsave(host_set lock)30793079+ */33173080void ata_bmdma_start(struct ata_queued_cmd *qc)33183081{33193082 if (qc->ap->flags & ATA_FLAG_MMIO)···33343073 ata_bmdma_start_pio(qc);33353074}3336307530763076+30773077+/**30783078+ * ata_bmdma_setup - Set up PCI IDE BMDMA transaction30793079+ * @qc: Info associated with this ATA transaction.30803080+ *30813081+ * Writes address of PRD table to device's PRD Table Address30823082+ * register, sets the DMA control register, and calls30833083+ * ops->exec_command() to start the transfer.30843084+ *30853085+ * May be used as the bmdma_setup() entry in ata_port_operations.30863086+ *30873087+ * LOCKING:30883088+ * spin_lock_irqsave(host_set lock)30893089+ */33373090void ata_bmdma_setup(struct ata_queued_cmd *qc)33383091{33393092 if (qc->ap->flags & ATA_FLAG_MMIO)···33553080 else33563081 ata_bmdma_setup_pio(qc);33573082}30833083+30843084+30853085+/**30863086+ * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.30873087+ * @ap: Port associated with this ATA transaction.30883088+ *30893089+ * Clear interrupt and error flags in DMA status register.30903090+ *30913091+ * May be used as the irq_clear() entry in ata_port_operations.30923092+ *30933093+ * LOCKING:30943094+ * spin_lock_irqsave(host_set lock)30953095+ */3358309633593097void ata_bmdma_irq_clear(struct ata_port *ap)33603098{···3381309333823094}3383309530963096+30973097+/**30983098+ * ata_bmdma_status - Read PCI IDE BMDMA status30993099+ * @ap: Port associated with this ATA transaction.31003100+ *31013101+ * Read and return BMDMA status register.31023102+ *31033103+ * May be used as the bmdma_status() entry in ata_port_operations.31043104+ *31053105+ * LOCKING:31063106+ * spin_lock_irqsave(host_set lock)31073107+ */31083108+33843109u8 ata_bmdma_status(struct ata_port *ap)33853110{33863111 u8 host_stat;···34043103 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);34053104 return host_stat;34063105}31063106+31073107+31083108+/**31093109+ * ata_bmdma_stop - Stop PCI IDE BMDMA transfer31103110+ * @ap: Port associated with this ATA transaction.31113111+ *31123112+ * Clears the ATA_DMA_START flag in the dma control register31133113+ *31143114+ * May be used as the bmdma_stop() entry in ata_port_operations.31153115+ *31163116+ * LOCKING:31173117+ * spin_lock_irqsave(host_set lock)31183118+ */3407311934083120void ata_bmdma_stop(struct ata_port *ap)34093121{···3517320335183204/**35193205 * ata_interrupt - Default ATA host interrupt handler35203520- * @irq: irq line35213521- * @dev_instance: pointer to our host information structure32063206+ * @irq: irq line (unused)32073207+ * @dev_instance: pointer to our ata_host_set information structure35223208 * @regs: unused35233209 *32103210+ * Default interrupt handler for PCI IDE devices. Calls32113211+ * ata_host_intr() for each port that is not disabled.32123212+ *35243213 * LOCKING:32143214+ * Obtains host_set lock during operation.35253215 *35263216 * RETURNS:32173217+ * IRQ_NONE or IRQ_HANDLED.35273218 *35283219 */35293220···36213302 ata_qc_complete(qc, ATA_ERR);36223303}3623330433053305+33063306+/**33073307+ * ata_port_start - Set port up for dma.33083308+ * @ap: Port to initialize33093309+ *33103310+ * Called just after data structures for each port are33113311+ * initialized. Allocates space for PRD table.33123312+ *33133313+ * May be used as the port_start() entry in ata_port_operations.33143314+ *33153315+ * LOCKING:33163316+ */33173317+36243318int ata_port_start (struct ata_port *ap)36253319{36263320 struct device *dev = ap->host_set->dev;···3646331436473315 return 0;36483316}33173317+33183318+33193319+/**33203320+ * ata_port_stop - Undo ata_port_start()33213321+ * @ap: Port to shut down33223322+ *33233323+ * Frees the PRD table.33243324+ *33253325+ * May be used as the port_stop() entry in ata_port_operations.33263326+ *33273327+ * LOCKING:33283328+ */3649332936503330void ata_port_stop (struct ata_port *ap)36513331{···37013357 * @ent: Probe information provided by low-level driver37023358 * @port_no: Port number associated with this ata_port37033359 *33603360+ * Initialize a new ata_port structure, and its associated33613361+ * scsi_host.33623362+ *37043363 * LOCKING:33643364+ * Inherited from caller.37053365 *37063366 */37073367···37603412 * @host_set: Collections of ports to which we add37613413 * @port_no: Port number associated with this host37623414 *34153415+ * Attach low-level ATA driver to system.34163416+ *37633417 * LOCKING:34183418+ * PCI/etc. bus probe sem.37643419 *37653420 * RETURNS:34213421+ * New ata_port on success, for NULL on error.37663422 *37673423 */37683424···37993447}3800344838013449/**38023802- * ata_device_add -38033803- * @ent:34503450+ * ata_device_add - Register hardware device with ATA and SCSI layers34513451+ * @ent: Probe information describing hardware device to be registered34523452+ *34533453+ * This function processes the information provided in the probe34543454+ * information struct @ent, allocates the necessary ATA and SCSI34553455+ * host information structures, initializes them, and registers34563456+ * everything with requisite kernel subsystems.34573457+ *34583458+ * This function requests irqs, probes the ATA bus, and probes34593459+ * the SCSI bus.38043460 *38053461 * LOCKING:34623462+ * PCI/etc. bus probe sem.38063463 *38073464 * RETURNS:34653465+ * Number of ports registered. Zero on error (no ports registered).38083466 *38093467 */38103468···39663604/**39673605 * ata_std_ports - initialize ioaddr with standard port offsets.39683606 * @ioaddr: IO address structure to be initialized36073607+ *36083608+ * Utility function which initializes data_addr, error_addr,36093609+ * feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,36103610+ * device_addr, status_addr, and command_addr to standard offsets36113611+ * relative to cmd_addr.36123612+ *36133613+ * Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.39693614 */36153615+39703616void ata_std_ports(struct ata_ioports *ioaddr)39713617{39723618 ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;···4015364540163646 return probe_ent;40173647}36483648+36493649+36503650+36513651+/**36523652+ * ata_pci_init_native_mode - Initialize native-mode driver36533653+ * @pdev: pci device to be initialized36543654+ * @port: array[2] of pointers to port info structures.36553655+ *36563656+ * Utility function which allocates and initializes an36573657+ * ata_probe_ent structure for a standard dual-port36583658+ * PIO-based IDE controller. The returned ata_probe_ent36593659+ * structure can be passed to ata_device_add(). The returned36603660+ * ata_probe_ent structure should then be freed with kfree().36613661+ */4018366240193663#ifdef CONFIG_PCI40203664struct ata_probe_ent *···41113727 * @port_info: Information from low-level host driver41123728 * @n_ports: Number of ports attached to host controller41133729 *37303730+ * This is a helper function which can be called from a driver's37313731+ * xxx_init_one() probe function if the hardware uses traditional37323732+ * IDE taskfile registers.37333733+ *37343734+ * This function calls pci_enable_device(), reserves its register37353735+ * regions, sets the dma mask, enables bus master mode, and calls37363736+ * ata_device_add()37373737+ *41143738 * LOCKING:41153739 * Inherited from PCI layer (may sleep).41163740 *41173741 * RETURNS:37423742+ * Zero on success, negative on errno-based value on error.41183743 *41193744 */41203745···43413948}43423949#endif /* CONFIG_PCI */4343395043444344-43454345-/**43464346- * ata_init -43474347- *43484348- * LOCKING:43494349- *43504350- * RETURNS:43514351- *43524352- */4353395143543952static int __init ata_init(void)43553953{
+1-1
drivers/scsi/libata-scsi.c
···947947}948948949949/**950950- * ata_scsiop_noop -950950+ * ata_scsiop_noop - Command handler that simply returns success.951951 * @args: device IDENTIFY data / SCSI command of interest.952952 * @rbuf: Response buffer, to which simulated SCSI cmd output is sent.953953 * @buflen: Response buffer length.
+58
include/linux/libata.h
···467467 return ap->ops->check_status(ap);468468}469469470470+471471+/**472472+ * ata_pause - Flush writes and pause 400 nanoseconds.473473+ * @ap: Port to wait for.474474+ *475475+ * LOCKING:476476+ * Inherited from caller.477477+ */478478+470479static inline void ata_pause(struct ata_port *ap)471480{472481 ata_altstatus(ap);473482 ndelay(400);474483}484484+485485+486486+/**487487+ * ata_busy_wait - Wait for a port status register488488+ * @ap: Port to wait for.489489+ *490490+ * Waits up to max*10 microseconds for the selected bits in the port's491491+ * status register to be cleared.492492+ * Returns final value of status register.493493+ *494494+ * LOCKING:495495+ * Inherited from caller.496496+ */475497476498static inline u8 ata_busy_wait(struct ata_port *ap, unsigned int bits,477499 unsigned int max)···508486509487 return status;510488}489489+490490+491491+/**492492+ * ata_wait_idle - Wait for a port to be idle.493493+ * @ap: Port to wait for.494494+ *495495+ * Waits up to 10ms for port's BUSY and DRQ signals to clear.496496+ * Returns final value of status register.497497+ *498498+ * LOCKING:499499+ * Inherited from caller.500500+ */511501512502static inline u8 ata_wait_idle(struct ata_port *ap)513503{···559525 tf->device = ATA_DEVICE_OBS | ATA_DEV1;560526}561527528528+529529+/**530530+ * ata_irq_on - Enable interrupts on a port.531531+ * @ap: Port on which interrupts are enabled.532532+ *533533+ * Enable interrupts on a legacy IDE device using MMIO or PIO,534534+ * wait for idle, clear any pending interrupts.535535+ *536536+ * LOCKING:537537+ * Inherited from caller.538538+ */539539+562540static inline u8 ata_irq_on(struct ata_port *ap)563541{564542 struct ata_ioports *ioaddr = &ap->ioaddr;···589543590544 return tmp;591545}546546+547547+548548+/**549549+ * ata_irq_ack - Acknowledge a device interrupt.550550+ * @ap: Port on which interrupts are enabled.551551+ *552552+ * Wait up to 10 ms for legacy IDE device to become idle (BUSY553553+ * or BUSY+DRQ clear). Obtain dma status and port status from554554+ * device. Clear the interrupt. Return port status.555555+ *556556+ * LOCKING:557557+ */592558593559static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)594560{