libata.h 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2003-2005 Red Hat, Inc. All rights reserved.
  4. * Copyright 2003-2005 Jeff Garzik
  5. *
  6. * libata documentation is available via 'make {ps|pdf}docs',
  7. * as Documentation/driver-api/libata.rst
  8. */
  9. #ifndef __LINUX_LIBATA_H__
  10. #define __LINUX_LIBATA_H__
  11. #include <linux/delay.h>
  12. #include <linux/jiffies.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/scatterlist.h>
  16. #include <linux/io.h>
  17. #include <linux/ata.h>
  18. #include <linux/workqueue.h>
  19. #include <scsi/scsi_host.h>
  20. #include <linux/acpi.h>
  21. #include <linux/cdrom.h>
  22. #include <linux/sched.h>
  23. #include <linux/async.h>
  24. /*
  25. * Define if arch has non-standard setup. This is a _PCI_ standard
  26. * not a legacy or ISA standard.
  27. */
  28. #ifdef CONFIG_ATA_NONSTANDARD
  29. #include <asm/libata-portmap.h>
  30. #else
  31. #define ATA_PRIMARY_IRQ(dev) 14
  32. #define ATA_SECONDARY_IRQ(dev) 15
  33. #endif
  34. /*
  35. * compile-time options: to be removed as soon as all the drivers are
  36. * converted to the new debugging mechanism
  37. */
  38. #undef ATA_IRQ_TRAP /* define to ack screaming irqs */
  39. #define ata_print_version_once(dev, version) \
  40. ({ \
  41. static bool __print_once; \
  42. \
  43. if (!__print_once) { \
  44. __print_once = true; \
  45. ata_print_version(dev, version); \
  46. } \
  47. })
  48. /* defines only for the constants which don't work well as enums */
  49. #define ATA_TAG_POISON 0xfafbfcfdU
  50. enum {
  51. /* various global constants */
  52. LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
  53. LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4, /* Worst case */
  54. ATA_DEF_QUEUE = 1,
  55. ATA_MAX_QUEUE = 32,
  56. ATA_TAG_INTERNAL = ATA_MAX_QUEUE,
  57. ATA_SHORT_PAUSE = 16,
  58. ATAPI_MAX_DRAIN = 16 << 10,
  59. ATA_ALL_DEVICES = (1 << ATA_MAX_DEVICES) - 1,
  60. ATA_SHT_EMULATED = 1,
  61. ATA_SHT_THIS_ID = -1,
  62. /* struct ata_taskfile flags */
  63. ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
  64. ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
  65. ATA_TFLAG_DEVICE = (1 << 2), /* enable r/w to device reg */
  66. ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
  67. ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
  68. ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
  69. ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
  70. /* struct ata_device stuff */
  71. ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
  72. ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
  73. ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
  74. ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
  75. ATA_DFLAG_FLUSH_EXT = (1 << 4), /* do FLUSH_EXT instead of FLUSH */
  76. ATA_DFLAG_ACPI_PENDING = (1 << 5), /* ACPI resume action pending */
  77. ATA_DFLAG_ACPI_FAILED = (1 << 6), /* ACPI on devcfg has failed */
  78. ATA_DFLAG_AN = (1 << 7), /* AN configured */
  79. ATA_DFLAG_TRUSTED = (1 << 8), /* device supports trusted send/recv */
  80. ATA_DFLAG_DMADIR = (1 << 10), /* device requires DMADIR */
  81. ATA_DFLAG_CFG_MASK = (1 << 12) - 1,
  82. ATA_DFLAG_PIO = (1 << 12), /* device limited to PIO mode */
  83. ATA_DFLAG_NCQ_OFF = (1 << 13), /* device limited to non-NCQ mode */
  84. ATA_DFLAG_SLEEPING = (1 << 15), /* device is sleeping */
  85. ATA_DFLAG_DUBIOUS_XFER = (1 << 16), /* data transfer not verified */
  86. ATA_DFLAG_NO_UNLOAD = (1 << 17), /* device doesn't support unload */
  87. ATA_DFLAG_UNLOCK_HPA = (1 << 18), /* unlock HPA */
  88. ATA_DFLAG_NCQ_SEND_RECV = (1 << 19), /* device supports NCQ SEND and RECV */
  89. ATA_DFLAG_NCQ_PRIO = (1 << 20), /* device supports NCQ priority */
  90. ATA_DFLAG_NCQ_PRIO_ENABLED = (1 << 21), /* Priority cmds sent to dev */
  91. ATA_DFLAG_INIT_MASK = (1 << 24) - 1,
  92. ATA_DFLAG_DETACH = (1 << 24),
  93. ATA_DFLAG_DETACHED = (1 << 25),
  94. ATA_DFLAG_DA = (1 << 26), /* device supports Device Attention */
  95. ATA_DFLAG_DEVSLP = (1 << 27), /* device supports Device Sleep */
  96. ATA_DFLAG_ACPI_DISABLED = (1 << 28), /* ACPI for the device is disabled */
  97. ATA_DFLAG_D_SENSE = (1 << 29), /* Descriptor sense requested */
  98. ATA_DFLAG_ZAC = (1 << 30), /* ZAC device */
  99. ATA_DFLAG_FEATURES_MASK = ATA_DFLAG_TRUSTED | ATA_DFLAG_DA | \
  100. ATA_DFLAG_DEVSLP | ATA_DFLAG_NCQ_SEND_RECV | \
  101. ATA_DFLAG_NCQ_PRIO,
  102. ATA_DEV_UNKNOWN = 0, /* unknown device */
  103. ATA_DEV_ATA = 1, /* ATA device */
  104. ATA_DEV_ATA_UNSUP = 2, /* ATA device (unsupported) */
  105. ATA_DEV_ATAPI = 3, /* ATAPI device */
  106. ATA_DEV_ATAPI_UNSUP = 4, /* ATAPI device (unsupported) */
  107. ATA_DEV_PMP = 5, /* SATA port multiplier */
  108. ATA_DEV_PMP_UNSUP = 6, /* SATA port multiplier (unsupported) */
  109. ATA_DEV_SEMB = 7, /* SEMB */
  110. ATA_DEV_SEMB_UNSUP = 8, /* SEMB (unsupported) */
  111. ATA_DEV_ZAC = 9, /* ZAC device */
  112. ATA_DEV_ZAC_UNSUP = 10, /* ZAC device (unsupported) */
  113. ATA_DEV_NONE = 11, /* no device */
  114. /* struct ata_link flags */
  115. /* NOTE: struct ata_force_param currently stores lflags in u16 */
  116. ATA_LFLAG_NO_HRST = (1 << 1), /* avoid hardreset */
  117. ATA_LFLAG_NO_SRST = (1 << 2), /* avoid softreset */
  118. ATA_LFLAG_ASSUME_ATA = (1 << 3), /* assume ATA class */
  119. ATA_LFLAG_ASSUME_SEMB = (1 << 4), /* assume SEMB class */
  120. ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
  121. ATA_LFLAG_NO_RETRY = (1 << 5), /* don't retry this link */
  122. ATA_LFLAG_DISABLED = (1 << 6), /* link is disabled */
  123. ATA_LFLAG_SW_ACTIVITY = (1 << 7), /* keep activity stats */
  124. ATA_LFLAG_NO_LPM = (1 << 8), /* disable LPM on this link */
  125. ATA_LFLAG_RST_ONCE = (1 << 9), /* limit recovery to one reset */
  126. ATA_LFLAG_CHANGED = (1 << 10), /* LPM state changed on this link */
  127. ATA_LFLAG_NO_DEBOUNCE_DELAY = (1 << 11), /* no debounce delay on link resume */
  128. /* struct ata_port flags */
  129. ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
  130. /* (doesn't imply presence) */
  131. ATA_FLAG_SATA = (1 << 1),
  132. ATA_FLAG_NO_LPM = (1 << 2), /* host not happy with LPM */
  133. ATA_FLAG_NO_LOG_PAGE = (1 << 5), /* do not issue log page read */
  134. ATA_FLAG_NO_ATAPI = (1 << 6), /* No ATAPI support */
  135. ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
  136. ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
  137. ATA_FLAG_PIO_POLLING = (1 << 9), /* use polling PIO if LLD
  138. * doesn't handle PIO interrupts */
  139. ATA_FLAG_NCQ = (1 << 10), /* host supports NCQ */
  140. ATA_FLAG_NO_POWEROFF_SPINDOWN = (1 << 11), /* don't spindown before poweroff */
  141. ATA_FLAG_NO_HIBERNATE_SPINDOWN = (1 << 12), /* don't spindown before hibernation */
  142. ATA_FLAG_DEBUGMSG = (1 << 13),
  143. ATA_FLAG_FPDMA_AA = (1 << 14), /* driver supports Auto-Activate */
  144. ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
  145. ATA_FLAG_NO_IORDY = (1 << 16), /* controller lacks iordy */
  146. ATA_FLAG_ACPI_SATA = (1 << 17), /* need native SATA ACPI layout */
  147. ATA_FLAG_AN = (1 << 18), /* controller supports AN */
  148. ATA_FLAG_PMP = (1 << 19), /* controller supports PMP */
  149. ATA_FLAG_FPDMA_AUX = (1 << 20), /* controller supports H2DFIS aux field */
  150. ATA_FLAG_EM = (1 << 21), /* driver supports enclosure
  151. * management */
  152. ATA_FLAG_SW_ACTIVITY = (1 << 22), /* driver supports sw activity
  153. * led */
  154. ATA_FLAG_NO_DIPM = (1 << 23), /* host not happy with DIPM */
  155. ATA_FLAG_SAS_HOST = (1 << 24), /* SAS host */
  156. /* bits 24:31 of ap->flags are reserved for LLD specific flags */
  157. /* struct ata_port pflags */
  158. ATA_PFLAG_EH_PENDING = (1 << 0), /* EH pending */
  159. ATA_PFLAG_EH_IN_PROGRESS = (1 << 1), /* EH in progress */
  160. ATA_PFLAG_FROZEN = (1 << 2), /* port is frozen */
  161. ATA_PFLAG_RECOVERED = (1 << 3), /* recovery action performed */
  162. ATA_PFLAG_LOADING = (1 << 4), /* boot/loading probe */
  163. ATA_PFLAG_SCSI_HOTPLUG = (1 << 6), /* SCSI hotplug scheduled */
  164. ATA_PFLAG_INITIALIZING = (1 << 7), /* being initialized, don't touch */
  165. ATA_PFLAG_RESETTING = (1 << 8), /* reset in progress */
  166. ATA_PFLAG_UNLOADING = (1 << 9), /* driver is being unloaded */
  167. ATA_PFLAG_UNLOADED = (1 << 10), /* driver is unloaded */
  168. ATA_PFLAG_RESUMING = (1 << 16), /* port is being resumed */
  169. ATA_PFLAG_SUSPENDED = (1 << 17), /* port is suspended (power) */
  170. ATA_PFLAG_PM_PENDING = (1 << 18), /* PM operation pending */
  171. ATA_PFLAG_INIT_GTM_VALID = (1 << 19), /* initial gtm data valid */
  172. ATA_PFLAG_PIO32 = (1 << 20), /* 32bit PIO */
  173. ATA_PFLAG_PIO32CHANGE = (1 << 21), /* 32bit PIO can be turned on/off */
  174. ATA_PFLAG_EXTERNAL = (1 << 22), /* eSATA/external port */
  175. /* struct ata_queued_cmd flags */
  176. ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */
  177. ATA_QCFLAG_DMAMAP = (1 << 1), /* SG table is DMA mapped */
  178. ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
  179. ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
  180. ATA_QCFLAG_CLEAR_EXCL = (1 << 5), /* clear excl_link on completion */
  181. ATA_QCFLAG_QUIET = (1 << 6), /* don't report device error */
  182. ATA_QCFLAG_RETRY = (1 << 7), /* retry after failure */
  183. ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */
  184. ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
  185. ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
  186. /* host set flags */
  187. ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host only */
  188. ATA_HOST_STARTED = (1 << 1), /* Host started */
  189. ATA_HOST_PARALLEL_SCAN = (1 << 2), /* Ports on this host can be scanned in parallel */
  190. ATA_HOST_IGNORE_ATA = (1 << 3), /* Ignore ATA devices on this host. */
  191. ATA_HOST_NO_PART = (1 << 4), /* Host does not support partial */
  192. ATA_HOST_NO_SSC = (1 << 5), /* Host does not support slumber */
  193. ATA_HOST_NO_DEVSLP = (1 << 6), /* Host does not support devslp */
  194. /* bits 24:31 of host->flags are reserved for LLD specific flags */
  195. /* various lengths of time */
  196. ATA_TMOUT_BOOT = 30000, /* heuristic */
  197. ATA_TMOUT_BOOT_QUICK = 7000, /* heuristic */
  198. ATA_TMOUT_INTERNAL_QUICK = 5000,
  199. ATA_TMOUT_MAX_PARK = 30000,
  200. /*
  201. * GoVault needs 2s and iVDR disk HHD424020F7SV00 800ms. 2s
  202. * is too much without parallel probing. Use 2s if parallel
  203. * probing is available, 800ms otherwise.
  204. */
  205. ATA_TMOUT_FF_WAIT_LONG = 2000,
  206. ATA_TMOUT_FF_WAIT = 800,
  207. /* Spec mandates to wait for ">= 2ms" before checking status
  208. * after reset. We wait 150ms, because that was the magic
  209. * delay used for ATAPI devices in Hale Landis's ATADRVR, for
  210. * the period of time between when the ATA command register is
  211. * written, and then status is checked. Because waiting for
  212. * "a while" before checking status is fine, post SRST, we
  213. * perform this magic delay here as well.
  214. *
  215. * Old drivers/ide uses the 2mS rule and then waits for ready.
  216. */
  217. ATA_WAIT_AFTER_RESET = 150,
  218. /* If PMP is supported, we have to do follow-up SRST. As some
  219. * PMPs don't send D2H Reg FIS after hardreset, LLDs are
  220. * advised to wait only for the following duration before
  221. * doing SRST.
  222. */
  223. ATA_TMOUT_PMP_SRST_WAIT = 10000,
  224. /* When the LPM policy is set to ATA_LPM_MAX_POWER, there might
  225. * be a spurious PHY event, so ignore the first PHY event that
  226. * occurs within 10s after the policy change.
  227. */
  228. ATA_TMOUT_SPURIOUS_PHY = 10000,
  229. /* ATA bus states */
  230. BUS_UNKNOWN = 0,
  231. BUS_DMA = 1,
  232. BUS_IDLE = 2,
  233. BUS_NOINTR = 3,
  234. BUS_NODATA = 4,
  235. BUS_TIMER = 5,
  236. BUS_PIO = 6,
  237. BUS_EDD = 7,
  238. BUS_IDENTIFY = 8,
  239. BUS_PACKET = 9,
  240. /* SATA port states */
  241. PORT_UNKNOWN = 0,
  242. PORT_ENABLED = 1,
  243. PORT_DISABLED = 2,
  244. /* encoding various smaller bitmaps into a single
  245. * unsigned int bitmap
  246. */
  247. ATA_NR_PIO_MODES = 7,
  248. ATA_NR_MWDMA_MODES = 5,
  249. ATA_NR_UDMA_MODES = 8,
  250. ATA_SHIFT_PIO = 0,
  251. ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
  252. ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
  253. ATA_SHIFT_PRIO = 6,
  254. ATA_PRIO_HIGH = 2,
  255. /* size of buffer to pad xfers ending on unaligned boundaries */
  256. ATA_DMA_PAD_SZ = 4,
  257. /* ering size */
  258. ATA_ERING_SIZE = 32,
  259. /* return values for ->qc_defer */
  260. ATA_DEFER_LINK = 1,
  261. ATA_DEFER_PORT = 2,
  262. /* desc_len for ata_eh_info and context */
  263. ATA_EH_DESC_LEN = 80,
  264. /* reset / recovery action types */
  265. ATA_EH_REVALIDATE = (1 << 0),
  266. ATA_EH_SOFTRESET = (1 << 1), /* meaningful only in ->prereset */
  267. ATA_EH_HARDRESET = (1 << 2), /* meaningful only in ->prereset */
  268. ATA_EH_RESET = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
  269. ATA_EH_ENABLE_LINK = (1 << 3),
  270. ATA_EH_PARK = (1 << 5), /* unload heads and stop I/O */
  271. ATA_EH_SET_ACTIVE = (1 << 6), /* Set a device to active power mode */
  272. ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE | ATA_EH_PARK |
  273. ATA_EH_SET_ACTIVE,
  274. ATA_EH_ALL_ACTIONS = ATA_EH_REVALIDATE | ATA_EH_RESET |
  275. ATA_EH_ENABLE_LINK,
  276. /* ata_eh_info->flags */
  277. ATA_EHI_HOTPLUGGED = (1 << 0), /* could have been hotplugged */
  278. ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
  279. ATA_EHI_QUIET = (1 << 3), /* be quiet */
  280. ATA_EHI_NO_RECOVERY = (1 << 4), /* no recovery */
  281. ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
  282. ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
  283. ATA_EHI_PRINTINFO = (1 << 18), /* print configuration info */
  284. ATA_EHI_SETMODE = (1 << 19), /* configure transfer mode */
  285. ATA_EHI_POST_SETMODE = (1 << 20), /* revalidating after setmode */
  286. ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
  287. /* mask of flags to transfer *to* the slave link */
  288. ATA_EHI_TO_SLAVE_MASK = ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET,
  289. /* max tries if error condition is still set after ->error_handler */
  290. ATA_EH_MAX_TRIES = 5,
  291. /* sometimes resuming a link requires several retries */
  292. ATA_LINK_RESUME_TRIES = 5,
  293. /* how hard are we gonna try to probe/recover devices */
  294. ATA_PROBE_MAX_TRIES = 3,
  295. ATA_EH_DEV_TRIES = 3,
  296. ATA_EH_PMP_TRIES = 5,
  297. ATA_EH_PMP_LINK_TRIES = 3,
  298. SATA_PMP_RW_TIMEOUT = 3000, /* PMP read/write timeout */
  299. /* This should match the actual table size of
  300. * ata_eh_cmd_timeout_table in libata-eh.c.
  301. */
  302. ATA_EH_CMD_TIMEOUT_TABLE_SIZE = 8,
  303. /* Horkage types. May be set by libata or controller on drives
  304. (some horkage may be drive/controller pair dependent */
  305. ATA_HORKAGE_DIAGNOSTIC = (1 << 0), /* Failed boot diag */
  306. ATA_HORKAGE_NODMA = (1 << 1), /* DMA problems */
  307. ATA_HORKAGE_NONCQ = (1 << 2), /* Don't use NCQ */
  308. ATA_HORKAGE_MAX_SEC_128 = (1 << 3), /* Limit max sects to 128 */
  309. ATA_HORKAGE_BROKEN_HPA = (1 << 4), /* Broken HPA */
  310. ATA_HORKAGE_DISABLE = (1 << 5), /* Disable it */
  311. ATA_HORKAGE_HPA_SIZE = (1 << 6), /* native size off by one */
  312. ATA_HORKAGE_IVB = (1 << 8), /* cbl det validity bit bugs */
  313. ATA_HORKAGE_STUCK_ERR = (1 << 9), /* stuck ERR on next PACKET */
  314. ATA_HORKAGE_BRIDGE_OK = (1 << 10), /* no bridge limits */
  315. ATA_HORKAGE_ATAPI_MOD16_DMA = (1 << 11), /* use ATAPI DMA for commands
  316. not multiple of 16 bytes */
  317. ATA_HORKAGE_FIRMWARE_WARN = (1 << 12), /* firmware update warning */
  318. ATA_HORKAGE_1_5_GBPS = (1 << 13), /* force 1.5 Gbps */
  319. ATA_HORKAGE_NOSETXFER = (1 << 14), /* skip SETXFER, SATA only */
  320. ATA_HORKAGE_BROKEN_FPDMA_AA = (1 << 15), /* skip AA */
  321. ATA_HORKAGE_DUMP_ID = (1 << 16), /* dump IDENTIFY data */
  322. ATA_HORKAGE_MAX_SEC_LBA48 = (1 << 17), /* Set max sects to 65535 */
  323. ATA_HORKAGE_ATAPI_DMADIR = (1 << 18), /* device requires dmadir */
  324. ATA_HORKAGE_NO_NCQ_TRIM = (1 << 19), /* don't use queued TRIM */
  325. ATA_HORKAGE_NOLPM = (1 << 20), /* don't use LPM */
  326. ATA_HORKAGE_WD_BROKEN_LPM = (1 << 21), /* some WDs have broken LPM */
  327. ATA_HORKAGE_ZERO_AFTER_TRIM = (1 << 22),/* guarantees zero after trim */
  328. ATA_HORKAGE_NO_DMA_LOG = (1 << 23), /* don't use DMA for log read */
  329. ATA_HORKAGE_NOTRIM = (1 << 24), /* don't use TRIM */
  330. ATA_HORKAGE_MAX_SEC_1024 = (1 << 25), /* Limit max sects to 1024 */
  331. ATA_HORKAGE_MAX_TRIM_128M = (1 << 26), /* Limit max trim size to 128M */
  332. ATA_HORKAGE_NO_NCQ_ON_ATI = (1 << 27), /* Disable NCQ on ATI chipset */
  333. ATA_HORKAGE_NO_ID_DEV_LOG = (1 << 28), /* Identify device log missing */
  334. ATA_HORKAGE_NO_LOG_DIR = (1 << 29), /* Do not read log directory */
  335. /* DMA mask for user DMA control: User visible values; DO NOT
  336. renumber */
  337. ATA_DMA_MASK_ATA = (1 << 0), /* DMA on ATA Disk */
  338. ATA_DMA_MASK_ATAPI = (1 << 1), /* DMA on ATAPI */
  339. ATA_DMA_MASK_CFA = (1 << 2), /* DMA on CF Card */
  340. /* ATAPI command types */
  341. ATAPI_READ = 0, /* READs */
  342. ATAPI_WRITE = 1, /* WRITEs */
  343. ATAPI_READ_CD = 2, /* READ CD [MSF] */
  344. ATAPI_PASS_THRU = 3, /* SAT pass-thru */
  345. ATAPI_MISC = 4, /* the rest */
  346. /* Timing constants */
  347. ATA_TIMING_SETUP = (1 << 0),
  348. ATA_TIMING_ACT8B = (1 << 1),
  349. ATA_TIMING_REC8B = (1 << 2),
  350. ATA_TIMING_CYC8B = (1 << 3),
  351. ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B |
  352. ATA_TIMING_CYC8B,
  353. ATA_TIMING_ACTIVE = (1 << 4),
  354. ATA_TIMING_RECOVER = (1 << 5),
  355. ATA_TIMING_DMACK_HOLD = (1 << 6),
  356. ATA_TIMING_CYCLE = (1 << 7),
  357. ATA_TIMING_UDMA = (1 << 8),
  358. ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B |
  359. ATA_TIMING_REC8B | ATA_TIMING_CYC8B |
  360. ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER |
  361. ATA_TIMING_DMACK_HOLD | ATA_TIMING_CYCLE |
  362. ATA_TIMING_UDMA,
  363. /* ACPI constants */
  364. ATA_ACPI_FILTER_SETXFER = 1 << 0,
  365. ATA_ACPI_FILTER_LOCK = 1 << 1,
  366. ATA_ACPI_FILTER_DIPM = 1 << 2,
  367. ATA_ACPI_FILTER_FPDMA_OFFSET = 1 << 3, /* FPDMA non-zero offset */
  368. ATA_ACPI_FILTER_FPDMA_AA = 1 << 4, /* FPDMA auto activate */
  369. ATA_ACPI_FILTER_DEFAULT = ATA_ACPI_FILTER_SETXFER |
  370. ATA_ACPI_FILTER_LOCK |
  371. ATA_ACPI_FILTER_DIPM,
  372. };
  373. enum ata_xfer_mask {
  374. ATA_MASK_PIO = ((1U << ATA_NR_PIO_MODES) - 1) << ATA_SHIFT_PIO,
  375. ATA_MASK_MWDMA = ((1U << ATA_NR_MWDMA_MODES) - 1) << ATA_SHIFT_MWDMA,
  376. ATA_MASK_UDMA = ((1U << ATA_NR_UDMA_MODES) - 1) << ATA_SHIFT_UDMA,
  377. };
  378. enum hsm_task_states {
  379. HSM_ST_IDLE, /* no command on going */
  380. HSM_ST_FIRST, /* (waiting the device to)
  381. write CDB or first data block */
  382. HSM_ST, /* (waiting the device to) transfer data */
  383. HSM_ST_LAST, /* (waiting the device to) complete command */
  384. HSM_ST_ERR, /* error */
  385. };
  386. enum ata_completion_errors {
  387. AC_ERR_OK = 0, /* no error */
  388. AC_ERR_DEV = (1 << 0), /* device reported error */
  389. AC_ERR_HSM = (1 << 1), /* host state machine violation */
  390. AC_ERR_TIMEOUT = (1 << 2), /* timeout */
  391. AC_ERR_MEDIA = (1 << 3), /* media error */
  392. AC_ERR_ATA_BUS = (1 << 4), /* ATA bus error */
  393. AC_ERR_HOST_BUS = (1 << 5), /* host bus error */
  394. AC_ERR_SYSTEM = (1 << 6), /* system error */
  395. AC_ERR_INVALID = (1 << 7), /* invalid argument */
  396. AC_ERR_OTHER = (1 << 8), /* unknown */
  397. AC_ERR_NODEV_HINT = (1 << 9), /* polling device detection hint */
  398. AC_ERR_NCQ = (1 << 10), /* marker for offending NCQ qc */
  399. };
  400. /*
  401. * Link power management policy: If you alter this, you also need to
  402. * alter libata-scsi.c (for the ascii descriptions)
  403. */
  404. enum ata_lpm_policy {
  405. ATA_LPM_UNKNOWN,
  406. ATA_LPM_MAX_POWER,
  407. ATA_LPM_MED_POWER,
  408. ATA_LPM_MED_POWER_WITH_DIPM, /* Med power + DIPM as win IRST does */
  409. ATA_LPM_MIN_POWER_WITH_PARTIAL, /* Min Power + partial and slumber */
  410. ATA_LPM_MIN_POWER, /* Min power + no partial (slumber only) */
  411. };
  412. enum ata_lpm_hints {
  413. ATA_LPM_EMPTY = (1 << 0), /* port empty/probing */
  414. ATA_LPM_HIPM = (1 << 1), /* may use HIPM */
  415. ATA_LPM_WAKE_ONLY = (1 << 2), /* only wake up link */
  416. };
  417. /* forward declarations */
  418. struct scsi_device;
  419. struct ata_port_operations;
  420. struct ata_port;
  421. struct ata_link;
  422. struct ata_queued_cmd;
  423. /* typedefs */
  424. typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
  425. typedef int (*ata_prereset_fn_t)(struct ata_link *link, unsigned long deadline);
  426. typedef int (*ata_reset_fn_t)(struct ata_link *link, unsigned int *classes,
  427. unsigned long deadline);
  428. typedef void (*ata_postreset_fn_t)(struct ata_link *link, unsigned int *classes);
  429. extern struct device_attribute dev_attr_unload_heads;
  430. #ifdef CONFIG_SATA_HOST
  431. extern struct device_attribute dev_attr_link_power_management_policy;
  432. extern struct device_attribute dev_attr_ncq_prio_supported;
  433. extern struct device_attribute dev_attr_ncq_prio_enable;
  434. extern struct device_attribute dev_attr_em_message_type;
  435. extern struct device_attribute dev_attr_em_message;
  436. extern struct device_attribute dev_attr_sw_activity;
  437. #endif
  438. enum sw_activity {
  439. OFF,
  440. BLINK_ON,
  441. BLINK_OFF,
  442. };
  443. struct ata_taskfile {
  444. unsigned long flags; /* ATA_TFLAG_xxx */
  445. u8 protocol; /* ATA_PROT_xxx */
  446. u8 ctl; /* control reg */
  447. u8 hob_feature; /* additional data */
  448. u8 hob_nsect; /* to support LBA48 */
  449. u8 hob_lbal;
  450. u8 hob_lbam;
  451. u8 hob_lbah;
  452. union {
  453. u8 error;
  454. u8 feature;
  455. };
  456. u8 nsect;
  457. u8 lbal;
  458. u8 lbam;
  459. u8 lbah;
  460. u8 device;
  461. union {
  462. u8 status;
  463. u8 command;
  464. };
  465. u32 auxiliary; /* auxiliary field */
  466. /* from SATA 3.1 and */
  467. /* ATA-8 ACS-3 */
  468. };
  469. #ifdef CONFIG_ATA_SFF
  470. struct ata_ioports {
  471. void __iomem *cmd_addr;
  472. void __iomem *data_addr;
  473. void __iomem *error_addr;
  474. void __iomem *feature_addr;
  475. void __iomem *nsect_addr;
  476. void __iomem *lbal_addr;
  477. void __iomem *lbam_addr;
  478. void __iomem *lbah_addr;
  479. void __iomem *device_addr;
  480. void __iomem *status_addr;
  481. void __iomem *command_addr;
  482. void __iomem *altstatus_addr;
  483. void __iomem *ctl_addr;
  484. #ifdef CONFIG_ATA_BMDMA
  485. void __iomem *bmdma_addr;
  486. #endif /* CONFIG_ATA_BMDMA */
  487. void __iomem *scr_addr;
  488. };
  489. #endif /* CONFIG_ATA_SFF */
  490. struct ata_host {
  491. spinlock_t lock;
  492. struct device *dev;
  493. void __iomem * const *iomap;
  494. unsigned int n_ports;
  495. unsigned int n_tags; /* nr of NCQ tags */
  496. void *private_data;
  497. struct ata_port_operations *ops;
  498. unsigned long flags;
  499. struct kref kref;
  500. struct mutex eh_mutex;
  501. struct task_struct *eh_owner;
  502. struct ata_port *simplex_claimed; /* channel owning the DMA */
  503. struct ata_port *ports[];
  504. };
  505. struct ata_queued_cmd {
  506. struct ata_port *ap;
  507. struct ata_device *dev;
  508. struct scsi_cmnd *scsicmd;
  509. void (*scsidone)(struct scsi_cmnd *);
  510. struct ata_taskfile tf;
  511. u8 cdb[ATAPI_CDB_LEN];
  512. unsigned long flags; /* ATA_QCFLAG_xxx */
  513. unsigned int tag; /* libata core tag */
  514. unsigned int hw_tag; /* driver tag */
  515. unsigned int n_elem;
  516. unsigned int orig_n_elem;
  517. int dma_dir;
  518. unsigned int sect_size;
  519. unsigned int nbytes;
  520. unsigned int extrabytes;
  521. unsigned int curbytes;
  522. struct scatterlist sgent;
  523. struct scatterlist *sg;
  524. struct scatterlist *cursg;
  525. unsigned int cursg_ofs;
  526. unsigned int err_mask;
  527. struct ata_taskfile result_tf;
  528. ata_qc_cb_t complete_fn;
  529. void *private_data;
  530. void *lldd_task;
  531. };
  532. struct ata_port_stats {
  533. unsigned long unhandled_irq;
  534. unsigned long idle_irq;
  535. unsigned long rw_reqbuf;
  536. };
  537. struct ata_ering_entry {
  538. unsigned int eflags;
  539. unsigned int err_mask;
  540. u64 timestamp;
  541. };
  542. struct ata_ering {
  543. int cursor;
  544. struct ata_ering_entry ring[ATA_ERING_SIZE];
  545. };
  546. struct ata_cpr {
  547. u8 num;
  548. u8 num_storage_elements;
  549. u64 start_lba;
  550. u64 num_lbas;
  551. };
  552. struct ata_cpr_log {
  553. u8 nr_cpr;
  554. struct ata_cpr cpr[];
  555. };
  556. struct ata_device {
  557. struct ata_link *link;
  558. unsigned int devno; /* 0 or 1 */
  559. unsigned int horkage; /* List of broken features */
  560. unsigned long flags; /* ATA_DFLAG_xxx */
  561. struct scsi_device *sdev; /* attached SCSI device */
  562. void *private_data;
  563. #ifdef CONFIG_ATA_ACPI
  564. union acpi_object *gtf_cache;
  565. unsigned int gtf_filter;
  566. #endif
  567. #ifdef CONFIG_SATA_ZPODD
  568. void *zpodd;
  569. #endif
  570. struct device tdev;
  571. /* n_sector is CLEAR_BEGIN, read comment above CLEAR_BEGIN */
  572. u64 n_sectors; /* size of device, if ATA */
  573. u64 n_native_sectors; /* native size, if ATA */
  574. unsigned int class; /* ATA_DEV_xxx */
  575. unsigned long unpark_deadline;
  576. u8 pio_mode;
  577. u8 dma_mode;
  578. u8 xfer_mode;
  579. unsigned int xfer_shift; /* ATA_SHIFT_xxx */
  580. unsigned int multi_count; /* sectors count for
  581. READ/WRITE MULTIPLE */
  582. unsigned int max_sectors; /* per-device max sectors */
  583. unsigned int cdb_len;
  584. /* per-dev xfer mask */
  585. unsigned int pio_mask;
  586. unsigned int mwdma_mask;
  587. unsigned int udma_mask;
  588. /* for CHS addressing */
  589. u16 cylinders; /* Number of cylinders */
  590. u16 heads; /* Number of heads */
  591. u16 sectors; /* Number of sectors per track */
  592. union {
  593. u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
  594. u32 gscr[SATA_PMP_GSCR_DWORDS]; /* PMP GSCR block */
  595. } ____cacheline_aligned;
  596. /* DEVSLP Timing Variables from Identify Device Data Log */
  597. u8 devslp_timing[ATA_LOG_DEVSLP_SIZE];
  598. /* NCQ send and receive log subcommand support */
  599. u8 ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_SIZE];
  600. u8 ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_SIZE];
  601. /* ZAC zone configuration */
  602. u32 zac_zoned_cap;
  603. u32 zac_zones_optimal_open;
  604. u32 zac_zones_optimal_nonseq;
  605. u32 zac_zones_max_open;
  606. /* Concurrent positioning ranges */
  607. struct ata_cpr_log *cpr_log;
  608. /* error history */
  609. int spdn_cnt;
  610. /* ering is CLEAR_END, read comment above CLEAR_END */
  611. struct ata_ering ering;
  612. };
  613. /* Fields between ATA_DEVICE_CLEAR_BEGIN and ATA_DEVICE_CLEAR_END are
  614. * cleared to zero on ata_dev_init().
  615. */
  616. #define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
  617. #define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
  618. struct ata_eh_info {
  619. struct ata_device *dev; /* offending device */
  620. u32 serror; /* SError from LLDD */
  621. unsigned int err_mask; /* port-wide err_mask */
  622. unsigned int action; /* ATA_EH_* action mask */
  623. unsigned int dev_action[ATA_MAX_DEVICES]; /* dev EH action */
  624. unsigned int flags; /* ATA_EHI_* flags */
  625. unsigned int probe_mask;
  626. char desc[ATA_EH_DESC_LEN];
  627. int desc_len;
  628. };
  629. struct ata_eh_context {
  630. struct ata_eh_info i;
  631. int tries[ATA_MAX_DEVICES];
  632. int cmd_timeout_idx[ATA_MAX_DEVICES]
  633. [ATA_EH_CMD_TIMEOUT_TABLE_SIZE];
  634. unsigned int classes[ATA_MAX_DEVICES];
  635. unsigned int did_probe_mask;
  636. unsigned int unloaded_mask;
  637. unsigned int saved_ncq_enabled;
  638. u8 saved_xfer_mode[ATA_MAX_DEVICES];
  639. /* timestamp for the last reset attempt or success */
  640. unsigned long last_reset;
  641. };
  642. struct ata_acpi_drive
  643. {
  644. u32 pio;
  645. u32 dma;
  646. } __packed;
  647. struct ata_acpi_gtm {
  648. struct ata_acpi_drive drive[2];
  649. u32 flags;
  650. } __packed;
  651. struct ata_link {
  652. struct ata_port *ap;
  653. int pmp; /* port multiplier port # */
  654. struct device tdev;
  655. unsigned int active_tag; /* active tag on this link */
  656. u32 sactive; /* active NCQ commands */
  657. unsigned int flags; /* ATA_LFLAG_xxx */
  658. u32 saved_scontrol; /* SControl on probe */
  659. unsigned int hw_sata_spd_limit;
  660. unsigned int sata_spd_limit;
  661. unsigned int sata_spd; /* current SATA PHY speed */
  662. enum ata_lpm_policy lpm_policy;
  663. /* record runtime error info, protected by host_set lock */
  664. struct ata_eh_info eh_info;
  665. /* EH context */
  666. struct ata_eh_context eh_context;
  667. struct ata_device device[ATA_MAX_DEVICES];
  668. unsigned long last_lpm_change; /* when last LPM change happened */
  669. };
  670. #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
  671. #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
  672. struct ata_port {
  673. struct Scsi_Host *scsi_host; /* our co-allocated scsi host */
  674. struct ata_port_operations *ops;
  675. spinlock_t *lock;
  676. /* Flags owned by the EH context. Only EH should touch these once the
  677. port is active */
  678. unsigned long flags; /* ATA_FLAG_xxx */
  679. /* Flags that change dynamically, protected by ap->lock */
  680. unsigned int pflags; /* ATA_PFLAG_xxx */
  681. unsigned int print_id; /* user visible unique port ID */
  682. unsigned int local_port_no; /* host local port num */
  683. unsigned int port_no; /* 0 based port no. inside the host */
  684. #ifdef CONFIG_ATA_SFF
  685. struct ata_ioports ioaddr; /* ATA cmd/ctl/dma register blocks */
  686. u8 ctl; /* cache of ATA control register */
  687. u8 last_ctl; /* Cache last written value */
  688. struct ata_link* sff_pio_task_link; /* link currently used */
  689. struct delayed_work sff_pio_task;
  690. #ifdef CONFIG_ATA_BMDMA
  691. struct ata_bmdma_prd *bmdma_prd; /* BMDMA SG list */
  692. dma_addr_t bmdma_prd_dma; /* and its DMA mapping */
  693. #endif /* CONFIG_ATA_BMDMA */
  694. #endif /* CONFIG_ATA_SFF */
  695. unsigned int pio_mask;
  696. unsigned int mwdma_mask;
  697. unsigned int udma_mask;
  698. unsigned int cbl; /* cable type; ATA_CBL_xxx */
  699. struct ata_queued_cmd qcmd[ATA_MAX_QUEUE + 1];
  700. u64 qc_active;
  701. int nr_active_links; /* #links with active qcs */
  702. struct ata_link link; /* host default link */
  703. struct ata_link *slave_link; /* see ata_slave_link_init() */
  704. int nr_pmp_links; /* nr of available PMP links */
  705. struct ata_link *pmp_link; /* array of PMP links */
  706. struct ata_link *excl_link; /* for PMP qc exclusion */
  707. struct ata_port_stats stats;
  708. struct ata_host *host;
  709. struct device *dev;
  710. struct device tdev;
  711. struct mutex scsi_scan_mutex;
  712. struct delayed_work hotplug_task;
  713. struct delayed_work scsi_rescan_task;
  714. unsigned int hsm_task_state;
  715. struct list_head eh_done_q;
  716. wait_queue_head_t eh_wait_q;
  717. int eh_tries;
  718. struct completion park_req_pending;
  719. pm_message_t pm_mesg;
  720. enum ata_lpm_policy target_lpm_policy;
  721. struct timer_list fastdrain_timer;
  722. unsigned int fastdrain_cnt;
  723. async_cookie_t cookie;
  724. int em_message_type;
  725. void *private_data;
  726. #ifdef CONFIG_ATA_ACPI
  727. struct ata_acpi_gtm __acpi_init_gtm; /* use ata_acpi_init_gtm() */
  728. #endif
  729. /* owned by EH */
  730. u8 sector_buf[ATA_SECT_SIZE] ____cacheline_aligned;
  731. };
  732. /* The following initializer overrides a method to NULL whether one of
  733. * its parent has the method defined or not. This is equivalent to
  734. * ERR_PTR(-ENOENT). Unfortunately, ERR_PTR doesn't render a constant
  735. * expression and thus can't be used as an initializer.
  736. */
  737. #define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
  738. struct ata_port_operations {
  739. /*
  740. * Command execution
  741. */
  742. int (*qc_defer)(struct ata_queued_cmd *qc);
  743. int (*check_atapi_dma)(struct ata_queued_cmd *qc);
  744. enum ata_completion_errors (*qc_prep)(struct ata_queued_cmd *qc);
  745. unsigned int (*qc_issue)(struct ata_queued_cmd *qc);
  746. bool (*qc_fill_rtf)(struct ata_queued_cmd *qc);
  747. /*
  748. * Configuration and exception handling
  749. */
  750. int (*cable_detect)(struct ata_port *ap);
  751. unsigned int (*mode_filter)(struct ata_device *dev, unsigned int xfer_mask);
  752. void (*set_piomode)(struct ata_port *ap, struct ata_device *dev);
  753. void (*set_dmamode)(struct ata_port *ap, struct ata_device *dev);
  754. int (*set_mode)(struct ata_link *link, struct ata_device **r_failed_dev);
  755. unsigned int (*read_id)(struct ata_device *dev, struct ata_taskfile *tf,
  756. __le16 *id);
  757. void (*dev_config)(struct ata_device *dev);
  758. void (*freeze)(struct ata_port *ap);
  759. void (*thaw)(struct ata_port *ap);
  760. ata_prereset_fn_t prereset;
  761. ata_reset_fn_t softreset;
  762. ata_reset_fn_t hardreset;
  763. ata_postreset_fn_t postreset;
  764. ata_prereset_fn_t pmp_prereset;
  765. ata_reset_fn_t pmp_softreset;
  766. ata_reset_fn_t pmp_hardreset;
  767. ata_postreset_fn_t pmp_postreset;
  768. void (*error_handler)(struct ata_port *ap);
  769. void (*lost_interrupt)(struct ata_port *ap);
  770. void (*post_internal_cmd)(struct ata_queued_cmd *qc);
  771. void (*sched_eh)(struct ata_port *ap);
  772. void (*end_eh)(struct ata_port *ap);
  773. /*
  774. * Optional features
  775. */
  776. int (*scr_read)(struct ata_link *link, unsigned int sc_reg, u32 *val);
  777. int (*scr_write)(struct ata_link *link, unsigned int sc_reg, u32 val);
  778. void (*pmp_attach)(struct ata_port *ap);
  779. void (*pmp_detach)(struct ata_port *ap);
  780. int (*set_lpm)(struct ata_link *link, enum ata_lpm_policy policy,
  781. unsigned hints);
  782. /*
  783. * Start, stop, suspend and resume
  784. */
  785. int (*port_suspend)(struct ata_port *ap, pm_message_t mesg);
  786. int (*port_resume)(struct ata_port *ap);
  787. int (*port_start)(struct ata_port *ap);
  788. void (*port_stop)(struct ata_port *ap);
  789. void (*host_stop)(struct ata_host *host);
  790. #ifdef CONFIG_ATA_SFF
  791. /*
  792. * SFF / taskfile oriented ops
  793. */
  794. void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
  795. void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
  796. u8 (*sff_check_status)(struct ata_port *ap);
  797. u8 (*sff_check_altstatus)(struct ata_port *ap);
  798. void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
  799. void (*sff_tf_read)(struct ata_port *ap, struct ata_taskfile *tf);
  800. void (*sff_exec_command)(struct ata_port *ap,
  801. const struct ata_taskfile *tf);
  802. unsigned int (*sff_data_xfer)(struct ata_queued_cmd *qc,
  803. unsigned char *buf, unsigned int buflen, int rw);
  804. void (*sff_irq_on)(struct ata_port *);
  805. bool (*sff_irq_check)(struct ata_port *);
  806. void (*sff_irq_clear)(struct ata_port *);
  807. void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
  808. #ifdef CONFIG_ATA_BMDMA
  809. void (*bmdma_setup)(struct ata_queued_cmd *qc);
  810. void (*bmdma_start)(struct ata_queued_cmd *qc);
  811. void (*bmdma_stop)(struct ata_queued_cmd *qc);
  812. u8 (*bmdma_status)(struct ata_port *ap);
  813. #endif /* CONFIG_ATA_BMDMA */
  814. #endif /* CONFIG_ATA_SFF */
  815. ssize_t (*em_show)(struct ata_port *ap, char *buf);
  816. ssize_t (*em_store)(struct ata_port *ap, const char *message,
  817. size_t size);
  818. ssize_t (*sw_activity_show)(struct ata_device *dev, char *buf);
  819. ssize_t (*sw_activity_store)(struct ata_device *dev,
  820. enum sw_activity val);
  821. ssize_t (*transmit_led_message)(struct ata_port *ap, u32 state,
  822. ssize_t size);
  823. /*
  824. * Obsolete
  825. */
  826. void (*phy_reset)(struct ata_port *ap);
  827. void (*eng_timeout)(struct ata_port *ap);
  828. /*
  829. * ->inherits must be the last field and all the preceding
  830. * fields must be pointers.
  831. */
  832. const struct ata_port_operations *inherits;
  833. };
  834. struct ata_port_info {
  835. unsigned long flags;
  836. unsigned long link_flags;
  837. unsigned int pio_mask;
  838. unsigned int mwdma_mask;
  839. unsigned int udma_mask;
  840. struct ata_port_operations *port_ops;
  841. void *private_data;
  842. };
  843. struct ata_timing {
  844. unsigned short mode; /* ATA mode */
  845. unsigned short setup; /* t1 */
  846. unsigned short act8b; /* t2 for 8-bit I/O */
  847. unsigned short rec8b; /* t2i for 8-bit I/O */
  848. unsigned short cyc8b; /* t0 for 8-bit I/O */
  849. unsigned short active; /* t2 or tD */
  850. unsigned short recover; /* t2i or tK */
  851. unsigned short dmack_hold; /* tj */
  852. unsigned short cycle; /* t0 */
  853. unsigned short udma; /* t2CYCTYP/2 */
  854. };
  855. /*
  856. * Core layer - drivers/ata/libata-core.c
  857. */
  858. extern struct ata_port_operations ata_dummy_port_ops;
  859. extern const struct ata_port_info ata_dummy_port_info;
  860. static inline bool ata_is_atapi(u8 prot)
  861. {
  862. return prot & ATA_PROT_FLAG_ATAPI;
  863. }
  864. static inline bool ata_is_pio(u8 prot)
  865. {
  866. return prot & ATA_PROT_FLAG_PIO;
  867. }
  868. static inline bool ata_is_dma(u8 prot)
  869. {
  870. return prot & ATA_PROT_FLAG_DMA;
  871. }
  872. static inline bool ata_is_ncq(u8 prot)
  873. {
  874. return prot & ATA_PROT_FLAG_NCQ;
  875. }
  876. static inline bool ata_is_data(u8 prot)
  877. {
  878. return prot & (ATA_PROT_FLAG_PIO | ATA_PROT_FLAG_DMA);
  879. }
  880. static inline int is_multi_taskfile(struct ata_taskfile *tf)
  881. {
  882. return (tf->command == ATA_CMD_READ_MULTI) ||
  883. (tf->command == ATA_CMD_WRITE_MULTI) ||
  884. (tf->command == ATA_CMD_READ_MULTI_EXT) ||
  885. (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
  886. (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
  887. }
  888. static inline int ata_port_is_dummy(struct ata_port *ap)
  889. {
  890. return ap->ops == &ata_dummy_port_ops;
  891. }
  892. extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
  893. extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
  894. int (*check_ready)(struct ata_link *link));
  895. extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
  896. unsigned long deadline);
  897. extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
  898. extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
  899. extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
  900. const struct ata_port_info * const * ppi, int n_ports);
  901. extern void ata_host_get(struct ata_host *host);
  902. extern void ata_host_put(struct ata_host *host);
  903. extern int ata_host_start(struct ata_host *host);
  904. extern int ata_host_register(struct ata_host *host,
  905. struct scsi_host_template *sht);
  906. extern int ata_host_activate(struct ata_host *host, int irq,
  907. irq_handler_t irq_handler, unsigned long irq_flags,
  908. struct scsi_host_template *sht);
  909. extern void ata_host_detach(struct ata_host *host);
  910. extern void ata_host_init(struct ata_host *, struct device *, struct ata_port_operations *);
  911. extern int ata_scsi_detect(struct scsi_host_template *sht);
  912. extern int ata_scsi_ioctl(struct scsi_device *dev, unsigned int cmd,
  913. void __user *arg);
  914. #ifdef CONFIG_COMPAT
  915. #define ATA_SCSI_COMPAT_IOCTL .compat_ioctl = ata_scsi_ioctl,
  916. #else
  917. #define ATA_SCSI_COMPAT_IOCTL /* empty */
  918. #endif
  919. extern int ata_scsi_queuecmd(struct Scsi_Host *h, struct scsi_cmnd *cmd);
  920. #if IS_REACHABLE(CONFIG_ATA)
  921. bool ata_scsi_dma_need_drain(struct request *rq);
  922. #else
  923. #define ata_scsi_dma_need_drain NULL
  924. #endif
  925. extern int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *dev,
  926. unsigned int cmd, void __user *arg);
  927. extern bool ata_link_online(struct ata_link *link);
  928. extern bool ata_link_offline(struct ata_link *link);
  929. #ifdef CONFIG_PM
  930. extern void ata_host_suspend(struct ata_host *host, pm_message_t mesg);
  931. extern void ata_host_resume(struct ata_host *host);
  932. extern void ata_sas_port_suspend(struct ata_port *ap);
  933. extern void ata_sas_port_resume(struct ata_port *ap);
  934. #else
  935. static inline void ata_sas_port_suspend(struct ata_port *ap)
  936. {
  937. }
  938. static inline void ata_sas_port_resume(struct ata_port *ap)
  939. {
  940. }
  941. #endif
  942. extern int ata_ratelimit(void);
  943. extern void ata_msleep(struct ata_port *ap, unsigned int msecs);
  944. extern u32 ata_wait_register(struct ata_port *ap, void __iomem *reg, u32 mask,
  945. u32 val, unsigned long interval, unsigned long timeout);
  946. extern int atapi_cmd_type(u8 opcode);
  947. extern unsigned int ata_pack_xfermask(unsigned int pio_mask,
  948. unsigned int mwdma_mask,
  949. unsigned int udma_mask);
  950. extern void ata_unpack_xfermask(unsigned int xfer_mask,
  951. unsigned int *pio_mask,
  952. unsigned int *mwdma_mask,
  953. unsigned int *udma_mask);
  954. extern u8 ata_xfer_mask2mode(unsigned int xfer_mask);
  955. extern unsigned int ata_xfer_mode2mask(u8 xfer_mode);
  956. extern int ata_xfer_mode2shift(u8 xfer_mode);
  957. extern const char *ata_mode_string(unsigned int xfer_mask);
  958. extern unsigned int ata_id_xfermask(const u16 *id);
  959. extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
  960. extern enum ata_completion_errors ata_noop_qc_prep(struct ata_queued_cmd *qc);
  961. extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
  962. unsigned int n_elem);
  963. extern unsigned int ata_dev_classify(const struct ata_taskfile *tf);
  964. extern unsigned int ata_port_classify(struct ata_port *ap,
  965. const struct ata_taskfile *tf);
  966. extern void ata_dev_disable(struct ata_device *adev);
  967. extern void ata_id_string(const u16 *id, unsigned char *s,
  968. unsigned int ofs, unsigned int len);
  969. extern void ata_id_c_string(const u16 *id, unsigned char *s,
  970. unsigned int ofs, unsigned int len);
  971. extern unsigned int ata_do_dev_read_id(struct ata_device *dev,
  972. struct ata_taskfile *tf, __le16 *id);
  973. extern void ata_qc_complete(struct ata_queued_cmd *qc);
  974. extern u64 ata_qc_get_active(struct ata_port *ap);
  975. extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd);
  976. extern int ata_std_bios_param(struct scsi_device *sdev,
  977. struct block_device *bdev,
  978. sector_t capacity, int geom[]);
  979. extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
  980. extern int ata_scsi_slave_alloc(struct scsi_device *sdev);
  981. extern int ata_scsi_slave_config(struct scsi_device *sdev);
  982. extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
  983. extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
  984. int queue_depth);
  985. extern int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev,
  986. struct scsi_device *sdev, int queue_depth);
  987. extern struct ata_device *ata_dev_pair(struct ata_device *adev);
  988. extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
  989. extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
  990. extern void ata_scsi_cmd_error_handler(struct Scsi_Host *host, struct ata_port *ap, struct list_head *eh_q);
  991. /*
  992. * SATA specific code - drivers/ata/libata-sata.c
  993. */
  994. #ifdef CONFIG_SATA_HOST
  995. extern const unsigned long sata_deb_timing_normal[];
  996. extern const unsigned long sata_deb_timing_hotplug[];
  997. extern const unsigned long sata_deb_timing_long[];
  998. static inline const unsigned long *
  999. sata_ehc_deb_timing(struct ata_eh_context *ehc)
  1000. {
  1001. if (ehc->i.flags & ATA_EHI_HOTPLUGGED)
  1002. return sata_deb_timing_hotplug;
  1003. else
  1004. return sata_deb_timing_normal;
  1005. }
  1006. extern int sata_scr_valid(struct ata_link *link);
  1007. extern int sata_scr_read(struct ata_link *link, int reg, u32 *val);
  1008. extern int sata_scr_write(struct ata_link *link, int reg, u32 val);
  1009. extern int sata_scr_write_flush(struct ata_link *link, int reg, u32 val);
  1010. extern int sata_set_spd(struct ata_link *link);
  1011. extern int sata_link_hardreset(struct ata_link *link,
  1012. const unsigned long *timing, unsigned long deadline,
  1013. bool *online, int (*check_ready)(struct ata_link *));
  1014. extern int sata_link_resume(struct ata_link *link, const unsigned long *params,
  1015. unsigned long deadline);
  1016. extern void ata_eh_analyze_ncq_error(struct ata_link *link);
  1017. #else
  1018. static inline const unsigned long *
  1019. sata_ehc_deb_timing(struct ata_eh_context *ehc)
  1020. {
  1021. return NULL;
  1022. }
  1023. static inline int sata_scr_valid(struct ata_link *link) { return 0; }
  1024. static inline int sata_scr_read(struct ata_link *link, int reg, u32 *val)
  1025. {
  1026. return -EOPNOTSUPP;
  1027. }
  1028. static inline int sata_scr_write(struct ata_link *link, int reg, u32 val)
  1029. {
  1030. return -EOPNOTSUPP;
  1031. }
  1032. static inline int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
  1033. {
  1034. return -EOPNOTSUPP;
  1035. }
  1036. static inline int sata_set_spd(struct ata_link *link) { return -EOPNOTSUPP; }
  1037. static inline int sata_link_hardreset(struct ata_link *link,
  1038. const unsigned long *timing,
  1039. unsigned long deadline,
  1040. bool *online,
  1041. int (*check_ready)(struct ata_link *))
  1042. {
  1043. if (online)
  1044. *online = false;
  1045. return -EOPNOTSUPP;
  1046. }
  1047. static inline int sata_link_resume(struct ata_link *link,
  1048. const unsigned long *params,
  1049. unsigned long deadline)
  1050. {
  1051. return -EOPNOTSUPP;
  1052. }
  1053. static inline void ata_eh_analyze_ncq_error(struct ata_link *link) { }
  1054. #endif
  1055. extern int sata_link_debounce(struct ata_link *link,
  1056. const unsigned long *params, unsigned long deadline);
  1057. extern int sata_link_scr_lpm(struct ata_link *link, enum ata_lpm_policy policy,
  1058. bool spm_wakeup);
  1059. extern int ata_slave_link_init(struct ata_port *ap);
  1060. extern void ata_sas_port_destroy(struct ata_port *);
  1061. extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
  1062. struct ata_port_info *, struct Scsi_Host *);
  1063. extern void ata_sas_async_probe(struct ata_port *ap);
  1064. extern int ata_sas_sync_probe(struct ata_port *ap);
  1065. extern int ata_sas_port_init(struct ata_port *);
  1066. extern int ata_sas_port_start(struct ata_port *ap);
  1067. extern int ata_sas_tport_add(struct device *parent, struct ata_port *ap);
  1068. extern void ata_sas_tport_delete(struct ata_port *ap);
  1069. extern void ata_sas_port_stop(struct ata_port *ap);
  1070. extern int ata_sas_slave_configure(struct scsi_device *, struct ata_port *);
  1071. extern int ata_sas_queuecmd(struct scsi_cmnd *cmd, struct ata_port *ap);
  1072. extern void ata_tf_to_fis(const struct ata_taskfile *tf,
  1073. u8 pmp, int is_cmd, u8 *fis);
  1074. extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
  1075. extern int ata_qc_complete_multiple(struct ata_port *ap, u64 qc_active);
  1076. extern bool sata_lpm_ignore_phy_events(struct ata_link *link);
  1077. extern int sata_async_notification(struct ata_port *ap);
  1078. extern int ata_cable_40wire(struct ata_port *ap);
  1079. extern int ata_cable_80wire(struct ata_port *ap);
  1080. extern int ata_cable_sata(struct ata_port *ap);
  1081. extern int ata_cable_ignore(struct ata_port *ap);
  1082. extern int ata_cable_unknown(struct ata_port *ap);
  1083. /* Timing helpers */
  1084. extern unsigned int ata_pio_need_iordy(const struct ata_device *);
  1085. extern u8 ata_timing_cycle2mode(unsigned int xfer_shift, int cycle);
  1086. /* PCI */
  1087. #ifdef CONFIG_PCI
  1088. struct pci_dev;
  1089. struct pci_bits {
  1090. unsigned int reg; /* PCI config register to read */
  1091. unsigned int width; /* 1 (8 bit), 2 (16 bit), 4 (32 bit) */
  1092. unsigned long mask;
  1093. unsigned long val;
  1094. };
  1095. extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
  1096. extern void ata_pci_shutdown_one(struct pci_dev *pdev);
  1097. extern void ata_pci_remove_one(struct pci_dev *pdev);
  1098. #ifdef CONFIG_PM
  1099. extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
  1100. extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
  1101. extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
  1102. extern int ata_pci_device_resume(struct pci_dev *pdev);
  1103. #endif /* CONFIG_PM */
  1104. #endif /* CONFIG_PCI */
  1105. struct platform_device;
  1106. extern int ata_platform_remove_one(struct platform_device *pdev);
  1107. /*
  1108. * ACPI - drivers/ata/libata-acpi.c
  1109. */
  1110. #ifdef CONFIG_ATA_ACPI
  1111. static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
  1112. {
  1113. if (ap->pflags & ATA_PFLAG_INIT_GTM_VALID)
  1114. return &ap->__acpi_init_gtm;
  1115. return NULL;
  1116. }
  1117. int ata_acpi_stm(struct ata_port *ap, const struct ata_acpi_gtm *stm);
  1118. int ata_acpi_gtm(struct ata_port *ap, struct ata_acpi_gtm *stm);
  1119. unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
  1120. const struct ata_acpi_gtm *gtm);
  1121. int ata_acpi_cbl_80wire(struct ata_port *ap, const struct ata_acpi_gtm *gtm);
  1122. #else
  1123. static inline const struct ata_acpi_gtm *ata_acpi_init_gtm(struct ata_port *ap)
  1124. {
  1125. return NULL;
  1126. }
  1127. static inline int ata_acpi_stm(const struct ata_port *ap,
  1128. struct ata_acpi_gtm *stm)
  1129. {
  1130. return -ENOSYS;
  1131. }
  1132. static inline int ata_acpi_gtm(const struct ata_port *ap,
  1133. struct ata_acpi_gtm *stm)
  1134. {
  1135. return -ENOSYS;
  1136. }
  1137. static inline unsigned int ata_acpi_gtm_xfermask(struct ata_device *dev,
  1138. const struct ata_acpi_gtm *gtm)
  1139. {
  1140. return 0;
  1141. }
  1142. static inline int ata_acpi_cbl_80wire(struct ata_port *ap,
  1143. const struct ata_acpi_gtm *gtm)
  1144. {
  1145. return 0;
  1146. }
  1147. #endif
  1148. /*
  1149. * EH - drivers/ata/libata-eh.c
  1150. */
  1151. extern void ata_port_schedule_eh(struct ata_port *ap);
  1152. extern void ata_port_wait_eh(struct ata_port *ap);
  1153. extern int ata_link_abort(struct ata_link *link);
  1154. extern int ata_port_abort(struct ata_port *ap);
  1155. extern int ata_port_freeze(struct ata_port *ap);
  1156. extern void ata_eh_freeze_port(struct ata_port *ap);
  1157. extern void ata_eh_thaw_port(struct ata_port *ap);
  1158. extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
  1159. extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
  1160. extern void ata_do_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
  1161. ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
  1162. ata_postreset_fn_t postreset);
  1163. extern void ata_std_error_handler(struct ata_port *ap);
  1164. extern void ata_std_sched_eh(struct ata_port *ap);
  1165. extern void ata_std_end_eh(struct ata_port *ap);
  1166. extern int ata_link_nr_enabled(struct ata_link *link);
  1167. /*
  1168. * Base operations to inherit from and initializers for sht
  1169. *
  1170. * Operations
  1171. *
  1172. * base : Common to all libata drivers.
  1173. * sata : SATA controllers w/ native interface.
  1174. * pmp : SATA controllers w/ PMP support.
  1175. * sff : SFF ATA controllers w/o BMDMA support.
  1176. * bmdma : SFF ATA controllers w/ BMDMA support.
  1177. *
  1178. * sht initializers
  1179. *
  1180. * BASE : Common to all libata drivers. The user must set
  1181. * sg_tablesize and dma_boundary.
  1182. * PIO : SFF ATA controllers w/ only PIO support.
  1183. * BMDMA : SFF ATA controllers w/ BMDMA support. sg_tablesize and
  1184. * dma_boundary are set to BMDMA limits.
  1185. * NCQ : SATA controllers supporting NCQ. The user must set
  1186. * sg_tablesize, dma_boundary and can_queue.
  1187. */
  1188. extern const struct ata_port_operations ata_base_port_ops;
  1189. extern const struct ata_port_operations sata_port_ops;
  1190. extern const struct attribute_group *ata_common_sdev_groups[];
  1191. /*
  1192. * All sht initializers (BASE, PIO, BMDMA, NCQ) must be instantiated
  1193. * by the edge drivers. Because the 'module' field of sht must be the
  1194. * edge driver's module reference, otherwise the driver can be unloaded
  1195. * even if the scsi_device is being accessed.
  1196. */
  1197. #define __ATA_BASE_SHT(drv_name) \
  1198. .module = THIS_MODULE, \
  1199. .name = drv_name, \
  1200. .ioctl = ata_scsi_ioctl, \
  1201. ATA_SCSI_COMPAT_IOCTL \
  1202. .queuecommand = ata_scsi_queuecmd, \
  1203. .dma_need_drain = ata_scsi_dma_need_drain, \
  1204. .this_id = ATA_SHT_THIS_ID, \
  1205. .emulated = ATA_SHT_EMULATED, \
  1206. .proc_name = drv_name, \
  1207. .slave_alloc = ata_scsi_slave_alloc, \
  1208. .slave_destroy = ata_scsi_slave_destroy, \
  1209. .bios_param = ata_std_bios_param, \
  1210. .unlock_native_capacity = ata_scsi_unlock_native_capacity,\
  1211. .max_sectors = ATA_MAX_SECTORS_LBA48
  1212. #define ATA_SUBBASE_SHT(drv_name) \
  1213. __ATA_BASE_SHT(drv_name), \
  1214. .can_queue = ATA_DEF_QUEUE, \
  1215. .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
  1216. .slave_configure = ata_scsi_slave_config
  1217. #define ATA_SUBBASE_SHT_QD(drv_name, drv_qd) \
  1218. __ATA_BASE_SHT(drv_name), \
  1219. .can_queue = drv_qd, \
  1220. .tag_alloc_policy = BLK_TAG_ALLOC_RR, \
  1221. .slave_configure = ata_scsi_slave_config
  1222. #define ATA_BASE_SHT(drv_name) \
  1223. ATA_SUBBASE_SHT(drv_name), \
  1224. .sdev_groups = ata_common_sdev_groups
  1225. #ifdef CONFIG_SATA_HOST
  1226. extern const struct attribute_group *ata_ncq_sdev_groups[];
  1227. #define ATA_NCQ_SHT(drv_name) \
  1228. ATA_SUBBASE_SHT(drv_name), \
  1229. .sdev_groups = ata_ncq_sdev_groups, \
  1230. .change_queue_depth = ata_scsi_change_queue_depth
  1231. #define ATA_NCQ_SHT_QD(drv_name, drv_qd) \
  1232. ATA_SUBBASE_SHT_QD(drv_name, drv_qd), \
  1233. .sdev_groups = ata_ncq_sdev_groups, \
  1234. .change_queue_depth = ata_scsi_change_queue_depth
  1235. #endif
  1236. /*
  1237. * PMP helpers
  1238. */
  1239. #ifdef CONFIG_SATA_PMP
  1240. static inline bool sata_pmp_supported(struct ata_port *ap)
  1241. {
  1242. return ap->flags & ATA_FLAG_PMP;
  1243. }
  1244. static inline bool sata_pmp_attached(struct ata_port *ap)
  1245. {
  1246. return ap->nr_pmp_links != 0;
  1247. }
  1248. static inline bool ata_is_host_link(const struct ata_link *link)
  1249. {
  1250. return link == &link->ap->link || link == link->ap->slave_link;
  1251. }
  1252. #else /* CONFIG_SATA_PMP */
  1253. static inline bool sata_pmp_supported(struct ata_port *ap)
  1254. {
  1255. return false;
  1256. }
  1257. static inline bool sata_pmp_attached(struct ata_port *ap)
  1258. {
  1259. return false;
  1260. }
  1261. static inline bool ata_is_host_link(const struct ata_link *link)
  1262. {
  1263. return true;
  1264. }
  1265. #endif /* CONFIG_SATA_PMP */
  1266. static inline int sata_srst_pmp(struct ata_link *link)
  1267. {
  1268. if (sata_pmp_supported(link->ap) && ata_is_host_link(link))
  1269. return SATA_PMP_CTRL_PORT;
  1270. return link->pmp;
  1271. }
  1272. #define ata_port_printk(level, ap, fmt, ...) \
  1273. pr_ ## level ("ata%u: " fmt, (ap)->print_id, ##__VA_ARGS__)
  1274. #define ata_port_err(ap, fmt, ...) \
  1275. ata_port_printk(err, ap, fmt, ##__VA_ARGS__)
  1276. #define ata_port_warn(ap, fmt, ...) \
  1277. ata_port_printk(warn, ap, fmt, ##__VA_ARGS__)
  1278. #define ata_port_notice(ap, fmt, ...) \
  1279. ata_port_printk(notice, ap, fmt, ##__VA_ARGS__)
  1280. #define ata_port_info(ap, fmt, ...) \
  1281. ata_port_printk(info, ap, fmt, ##__VA_ARGS__)
  1282. #define ata_port_dbg(ap, fmt, ...) \
  1283. ata_port_printk(debug, ap, fmt, ##__VA_ARGS__)
  1284. #define ata_link_printk(level, link, fmt, ...) \
  1285. do { \
  1286. if (sata_pmp_attached((link)->ap) || \
  1287. (link)->ap->slave_link) \
  1288. pr_ ## level ("ata%u.%02u: " fmt, \
  1289. (link)->ap->print_id, \
  1290. (link)->pmp, \
  1291. ##__VA_ARGS__); \
  1292. else \
  1293. pr_ ## level ("ata%u: " fmt, \
  1294. (link)->ap->print_id, \
  1295. ##__VA_ARGS__); \
  1296. } while (0)
  1297. #define ata_link_err(link, fmt, ...) \
  1298. ata_link_printk(err, link, fmt, ##__VA_ARGS__)
  1299. #define ata_link_warn(link, fmt, ...) \
  1300. ata_link_printk(warn, link, fmt, ##__VA_ARGS__)
  1301. #define ata_link_notice(link, fmt, ...) \
  1302. ata_link_printk(notice, link, fmt, ##__VA_ARGS__)
  1303. #define ata_link_info(link, fmt, ...) \
  1304. ata_link_printk(info, link, fmt, ##__VA_ARGS__)
  1305. #define ata_link_dbg(link, fmt, ...) \
  1306. ata_link_printk(debug, link, fmt, ##__VA_ARGS__)
  1307. #define ata_dev_printk(level, dev, fmt, ...) \
  1308. pr_ ## level("ata%u.%02u: " fmt, \
  1309. (dev)->link->ap->print_id, \
  1310. (dev)->link->pmp + (dev)->devno, \
  1311. ##__VA_ARGS__)
  1312. #define ata_dev_err(dev, fmt, ...) \
  1313. ata_dev_printk(err, dev, fmt, ##__VA_ARGS__)
  1314. #define ata_dev_warn(dev, fmt, ...) \
  1315. ata_dev_printk(warn, dev, fmt, ##__VA_ARGS__)
  1316. #define ata_dev_notice(dev, fmt, ...) \
  1317. ata_dev_printk(notice, dev, fmt, ##__VA_ARGS__)
  1318. #define ata_dev_info(dev, fmt, ...) \
  1319. ata_dev_printk(info, dev, fmt, ##__VA_ARGS__)
  1320. #define ata_dev_dbg(dev, fmt, ...) \
  1321. ata_dev_printk(debug, dev, fmt, ##__VA_ARGS__)
  1322. void ata_print_version(const struct device *dev, const char *version);
  1323. /*
  1324. * ata_eh_info helpers
  1325. */
  1326. extern __printf(2, 3)
  1327. void __ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
  1328. extern __printf(2, 3)
  1329. void ata_ehi_push_desc(struct ata_eh_info *ehi, const char *fmt, ...);
  1330. extern void ata_ehi_clear_desc(struct ata_eh_info *ehi);
  1331. static inline void ata_ehi_hotplugged(struct ata_eh_info *ehi)
  1332. {
  1333. ehi->probe_mask |= (1 << ATA_MAX_DEVICES) - 1;
  1334. ehi->flags |= ATA_EHI_HOTPLUGGED;
  1335. ehi->action |= ATA_EH_RESET | ATA_EH_ENABLE_LINK;
  1336. ehi->err_mask |= AC_ERR_ATA_BUS;
  1337. }
  1338. /*
  1339. * port description helpers
  1340. */
  1341. extern __printf(2, 3)
  1342. void ata_port_desc(struct ata_port *ap, const char *fmt, ...);
  1343. #ifdef CONFIG_PCI
  1344. extern void ata_port_pbar_desc(struct ata_port *ap, int bar, ssize_t offset,
  1345. const char *name);
  1346. #endif
  1347. static inline bool ata_tag_internal(unsigned int tag)
  1348. {
  1349. return tag == ATA_TAG_INTERNAL;
  1350. }
  1351. static inline bool ata_tag_valid(unsigned int tag)
  1352. {
  1353. return tag < ATA_MAX_QUEUE || ata_tag_internal(tag);
  1354. }
  1355. #define __ata_qc_for_each(ap, qc, tag, max_tag, fn) \
  1356. for ((tag) = 0; (tag) < (max_tag) && \
  1357. ({ qc = fn((ap), (tag)); 1; }); (tag)++) \
  1358. /*
  1359. * Internal use only, iterate commands ignoring error handling and
  1360. * status of 'qc'.
  1361. */
  1362. #define ata_qc_for_each_raw(ap, qc, tag) \
  1363. __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, __ata_qc_from_tag)
  1364. /*
  1365. * Iterate all potential commands that can be queued
  1366. */
  1367. #define ata_qc_for_each(ap, qc, tag) \
  1368. __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE, ata_qc_from_tag)
  1369. /*
  1370. * Like ata_qc_for_each, but with the internal tag included
  1371. */
  1372. #define ata_qc_for_each_with_internal(ap, qc, tag) \
  1373. __ata_qc_for_each(ap, qc, tag, ATA_MAX_QUEUE + 1, ata_qc_from_tag)
  1374. /*
  1375. * device helpers
  1376. */
  1377. static inline unsigned int ata_class_enabled(unsigned int class)
  1378. {
  1379. return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI ||
  1380. class == ATA_DEV_PMP || class == ATA_DEV_SEMB ||
  1381. class == ATA_DEV_ZAC;
  1382. }
  1383. static inline unsigned int ata_class_disabled(unsigned int class)
  1384. {
  1385. return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP ||
  1386. class == ATA_DEV_PMP_UNSUP || class == ATA_DEV_SEMB_UNSUP ||
  1387. class == ATA_DEV_ZAC_UNSUP;
  1388. }
  1389. static inline unsigned int ata_class_absent(unsigned int class)
  1390. {
  1391. return !ata_class_enabled(class) && !ata_class_disabled(class);
  1392. }
  1393. static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
  1394. {
  1395. return ata_class_enabled(dev->class);
  1396. }
  1397. static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
  1398. {
  1399. return ata_class_disabled(dev->class);
  1400. }
  1401. static inline unsigned int ata_dev_absent(const struct ata_device *dev)
  1402. {
  1403. return ata_class_absent(dev->class);
  1404. }
  1405. /*
  1406. * link helpers
  1407. */
  1408. static inline int ata_link_max_devices(const struct ata_link *link)
  1409. {
  1410. if (ata_is_host_link(link) && link->ap->flags & ATA_FLAG_SLAVE_POSS)
  1411. return 2;
  1412. return 1;
  1413. }
  1414. static inline int ata_link_active(struct ata_link *link)
  1415. {
  1416. return ata_tag_valid(link->active_tag) || link->sactive;
  1417. }
  1418. /*
  1419. * Iterators
  1420. *
  1421. * ATA_LITER_* constants are used to select link iteration mode and
  1422. * ATA_DITER_* device iteration mode.
  1423. *
  1424. * For a custom iteration directly using ata_{link|dev}_next(), if
  1425. * @link or @dev, respectively, is NULL, the first element is
  1426. * returned. @dev and @link can be any valid device or link and the
  1427. * next element according to the iteration mode will be returned.
  1428. * After the last element, NULL is returned.
  1429. */
  1430. enum ata_link_iter_mode {
  1431. ATA_LITER_EDGE, /* if present, PMP links only; otherwise,
  1432. * host link. no slave link */
  1433. ATA_LITER_HOST_FIRST, /* host link followed by PMP or slave links */
  1434. ATA_LITER_PMP_FIRST, /* PMP links followed by host link,
  1435. * slave link still comes after host link */
  1436. };
  1437. enum ata_dev_iter_mode {
  1438. ATA_DITER_ENABLED,
  1439. ATA_DITER_ENABLED_REVERSE,
  1440. ATA_DITER_ALL,
  1441. ATA_DITER_ALL_REVERSE,
  1442. };
  1443. extern struct ata_link *ata_link_next(struct ata_link *link,
  1444. struct ata_port *ap,
  1445. enum ata_link_iter_mode mode);
  1446. extern struct ata_device *ata_dev_next(struct ata_device *dev,
  1447. struct ata_link *link,
  1448. enum ata_dev_iter_mode mode);
  1449. /*
  1450. * Shortcut notation for iterations
  1451. *
  1452. * ata_for_each_link() iterates over each link of @ap according to
  1453. * @mode. @link points to the current link in the loop. @link is
  1454. * NULL after loop termination. ata_for_each_dev() works the same way
  1455. * except that it iterates over each device of @link.
  1456. *
  1457. * Note that the mode prefixes ATA_{L|D}ITER_ shouldn't need to be
  1458. * specified when using the following shorthand notations. Only the
  1459. * mode itself (EDGE, HOST_FIRST, ENABLED, etc...) should be
  1460. * specified. This not only increases brevity but also makes it
  1461. * impossible to use ATA_LITER_* for device iteration or vice-versa.
  1462. */
  1463. #define ata_for_each_link(link, ap, mode) \
  1464. for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
  1465. (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
  1466. #define ata_for_each_dev(dev, link, mode) \
  1467. for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
  1468. (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
  1469. /**
  1470. * ata_ncq_enabled - Test whether NCQ is enabled
  1471. * @dev: ATA device to test for
  1472. *
  1473. * LOCKING:
  1474. * spin_lock_irqsave(host lock)
  1475. *
  1476. * RETURNS:
  1477. * 1 if NCQ is enabled for @dev, 0 otherwise.
  1478. */
  1479. static inline int ata_ncq_enabled(struct ata_device *dev)
  1480. {
  1481. if (!IS_ENABLED(CONFIG_SATA_HOST))
  1482. return 0;
  1483. return (dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
  1484. ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ;
  1485. }
  1486. static inline bool ata_fpdma_dsm_supported(struct ata_device *dev)
  1487. {
  1488. return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
  1489. (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_DSM_OFFSET] &
  1490. ATA_LOG_NCQ_SEND_RECV_DSM_TRIM);
  1491. }
  1492. static inline bool ata_fpdma_read_log_supported(struct ata_device *dev)
  1493. {
  1494. return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
  1495. (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_RD_LOG_OFFSET] &
  1496. ATA_LOG_NCQ_SEND_RECV_RD_LOG_SUPPORTED);
  1497. }
  1498. static inline bool ata_fpdma_zac_mgmt_in_supported(struct ata_device *dev)
  1499. {
  1500. return (dev->flags & ATA_DFLAG_NCQ_SEND_RECV) &&
  1501. (dev->ncq_send_recv_cmds[ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_OFFSET] &
  1502. ATA_LOG_NCQ_SEND_RECV_ZAC_MGMT_IN_SUPPORTED);
  1503. }
  1504. static inline bool ata_fpdma_zac_mgmt_out_supported(struct ata_device *dev)
  1505. {
  1506. return (dev->ncq_non_data_cmds[ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OFFSET] &
  1507. ATA_LOG_NCQ_NON_DATA_ZAC_MGMT_OUT);
  1508. }
  1509. static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
  1510. {
  1511. qc->tf.ctl |= ATA_NIEN;
  1512. }
  1513. static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
  1514. unsigned int tag)
  1515. {
  1516. if (ata_tag_valid(tag))
  1517. return &ap->qcmd[tag];
  1518. return NULL;
  1519. }
  1520. static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
  1521. unsigned int tag)
  1522. {
  1523. struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
  1524. if (unlikely(!qc) || !ap->ops->error_handler)
  1525. return qc;
  1526. if ((qc->flags & (ATA_QCFLAG_ACTIVE |
  1527. ATA_QCFLAG_FAILED)) == ATA_QCFLAG_ACTIVE)
  1528. return qc;
  1529. return NULL;
  1530. }
  1531. static inline unsigned int ata_qc_raw_nbytes(struct ata_queued_cmd *qc)
  1532. {
  1533. return qc->nbytes - min(qc->extrabytes, qc->nbytes);
  1534. }
  1535. static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
  1536. {
  1537. memset(tf, 0, sizeof(*tf));
  1538. #ifdef CONFIG_ATA_SFF
  1539. tf->ctl = dev->link->ap->ctl;
  1540. #else
  1541. tf->ctl = ATA_DEVCTL_OBS;
  1542. #endif
  1543. if (dev->devno == 0)
  1544. tf->device = ATA_DEVICE_OBS;
  1545. else
  1546. tf->device = ATA_DEVICE_OBS | ATA_DEV1;
  1547. }
  1548. static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
  1549. {
  1550. qc->dma_dir = DMA_NONE;
  1551. qc->sg = NULL;
  1552. qc->flags = 0;
  1553. qc->cursg = NULL;
  1554. qc->cursg_ofs = 0;
  1555. qc->nbytes = qc->extrabytes = qc->curbytes = 0;
  1556. qc->n_elem = 0;
  1557. qc->err_mask = 0;
  1558. qc->sect_size = ATA_SECT_SIZE;
  1559. ata_tf_init(qc->dev, &qc->tf);
  1560. /* init result_tf such that it indicates normal completion */
  1561. qc->result_tf.command = ATA_DRDY;
  1562. qc->result_tf.feature = 0;
  1563. }
  1564. static inline int ata_try_flush_cache(const struct ata_device *dev)
  1565. {
  1566. return ata_id_wcache_enabled(dev->id) ||
  1567. ata_id_has_flush(dev->id) ||
  1568. ata_id_has_flush_ext(dev->id);
  1569. }
  1570. static inline unsigned int ac_err_mask(u8 status)
  1571. {
  1572. if (status & (ATA_BUSY | ATA_DRQ))
  1573. return AC_ERR_HSM;
  1574. if (status & (ATA_ERR | ATA_DF))
  1575. return AC_ERR_DEV;
  1576. return 0;
  1577. }
  1578. static inline unsigned int __ac_err_mask(u8 status)
  1579. {
  1580. unsigned int mask = ac_err_mask(status);
  1581. if (mask == 0)
  1582. return AC_ERR_OTHER;
  1583. return mask;
  1584. }
  1585. static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
  1586. {
  1587. return *(struct ata_port **)&host->hostdata[0];
  1588. }
  1589. static inline int ata_check_ready(u8 status)
  1590. {
  1591. if (!(status & ATA_BUSY))
  1592. return 1;
  1593. /* 0xff indicates either no device or device not ready */
  1594. if (status == 0xff)
  1595. return -ENODEV;
  1596. return 0;
  1597. }
  1598. static inline unsigned long ata_deadline(unsigned long from_jiffies,
  1599. unsigned long timeout_msecs)
  1600. {
  1601. return from_jiffies + msecs_to_jiffies(timeout_msecs);
  1602. }
  1603. /* Don't open code these in drivers as there are traps. Firstly the range may
  1604. change in future hardware and specs, secondly 0xFF means 'no DMA' but is
  1605. > UDMA_0. Dyma ddreigiau */
  1606. static inline int ata_using_mwdma(struct ata_device *adev)
  1607. {
  1608. if (adev->dma_mode >= XFER_MW_DMA_0 && adev->dma_mode <= XFER_MW_DMA_4)
  1609. return 1;
  1610. return 0;
  1611. }
  1612. static inline int ata_using_udma(struct ata_device *adev)
  1613. {
  1614. if (adev->dma_mode >= XFER_UDMA_0 && adev->dma_mode <= XFER_UDMA_7)
  1615. return 1;
  1616. return 0;
  1617. }
  1618. static inline int ata_dma_enabled(struct ata_device *adev)
  1619. {
  1620. return (adev->dma_mode == 0xFF ? 0 : 1);
  1621. }
  1622. /**************************************************************************
  1623. * PATA timings - drivers/ata/libata-pata-timings.c
  1624. */
  1625. extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
  1626. extern int ata_timing_compute(struct ata_device *, unsigned short,
  1627. struct ata_timing *, int, int);
  1628. extern void ata_timing_merge(const struct ata_timing *,
  1629. const struct ata_timing *, struct ata_timing *,
  1630. unsigned int);
  1631. /**************************************************************************
  1632. * PMP - drivers/ata/libata-pmp.c
  1633. */
  1634. #ifdef CONFIG_SATA_PMP
  1635. extern const struct ata_port_operations sata_pmp_port_ops;
  1636. extern int sata_pmp_qc_defer_cmd_switch(struct ata_queued_cmd *qc);
  1637. extern void sata_pmp_error_handler(struct ata_port *ap);
  1638. #else /* CONFIG_SATA_PMP */
  1639. #define sata_pmp_port_ops sata_port_ops
  1640. #define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
  1641. #define sata_pmp_error_handler ata_std_error_handler
  1642. #endif /* CONFIG_SATA_PMP */
  1643. /**************************************************************************
  1644. * SFF - drivers/ata/libata-sff.c
  1645. */
  1646. #ifdef CONFIG_ATA_SFF
  1647. extern const struct ata_port_operations ata_sff_port_ops;
  1648. extern const struct ata_port_operations ata_bmdma32_port_ops;
  1649. /* PIO only, sg_tablesize and dma_boundary limits can be removed */
  1650. #define ATA_PIO_SHT(drv_name) \
  1651. ATA_BASE_SHT(drv_name), \
  1652. .sg_tablesize = LIBATA_MAX_PRD, \
  1653. .dma_boundary = ATA_DMA_BOUNDARY
  1654. extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
  1655. extern u8 ata_sff_check_status(struct ata_port *ap);
  1656. extern void ata_sff_pause(struct ata_port *ap);
  1657. extern void ata_sff_dma_pause(struct ata_port *ap);
  1658. extern int ata_sff_busy_sleep(struct ata_port *ap,
  1659. unsigned long timeout_pat, unsigned long timeout);
  1660. extern int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline);
  1661. extern void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
  1662. extern void ata_sff_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
  1663. extern void ata_sff_exec_command(struct ata_port *ap,
  1664. const struct ata_taskfile *tf);
  1665. extern unsigned int ata_sff_data_xfer(struct ata_queued_cmd *qc,
  1666. unsigned char *buf, unsigned int buflen, int rw);
  1667. extern unsigned int ata_sff_data_xfer32(struct ata_queued_cmd *qc,
  1668. unsigned char *buf, unsigned int buflen, int rw);
  1669. extern void ata_sff_irq_on(struct ata_port *ap);
  1670. extern void ata_sff_irq_clear(struct ata_port *ap);
  1671. extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
  1672. u8 status, int in_wq);
  1673. extern void ata_sff_queue_work(struct work_struct *work);
  1674. extern void ata_sff_queue_delayed_work(struct delayed_work *dwork,
  1675. unsigned long delay);
  1676. extern void ata_sff_queue_pio_task(struct ata_link *link, unsigned long delay);
  1677. extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
  1678. extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
  1679. extern unsigned int ata_sff_port_intr(struct ata_port *ap,
  1680. struct ata_queued_cmd *qc);
  1681. extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
  1682. extern void ata_sff_lost_interrupt(struct ata_port *ap);
  1683. extern void ata_sff_freeze(struct ata_port *ap);
  1684. extern void ata_sff_thaw(struct ata_port *ap);
  1685. extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
  1686. extern unsigned int ata_sff_dev_classify(struct ata_device *dev, int present,
  1687. u8 *r_err);
  1688. extern int ata_sff_wait_after_reset(struct ata_link *link, unsigned int devmask,
  1689. unsigned long deadline);
  1690. extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
  1691. unsigned long deadline);
  1692. extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
  1693. unsigned long deadline);
  1694. extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
  1695. extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
  1696. extern void ata_sff_error_handler(struct ata_port *ap);
  1697. extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
  1698. #ifdef CONFIG_PCI
  1699. extern int ata_pci_sff_init_host(struct ata_host *host);
  1700. extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
  1701. const struct ata_port_info * const * ppi,
  1702. struct ata_host **r_host);
  1703. extern int ata_pci_sff_activate_host(struct ata_host *host,
  1704. irq_handler_t irq_handler,
  1705. struct scsi_host_template *sht);
  1706. extern int ata_pci_sff_init_one(struct pci_dev *pdev,
  1707. const struct ata_port_info * const * ppi,
  1708. struct scsi_host_template *sht, void *host_priv, int hflags);
  1709. #endif /* CONFIG_PCI */
  1710. #ifdef CONFIG_ATA_BMDMA
  1711. extern const struct ata_port_operations ata_bmdma_port_ops;
  1712. #define ATA_BMDMA_SHT(drv_name) \
  1713. ATA_BASE_SHT(drv_name), \
  1714. .sg_tablesize = LIBATA_MAX_PRD, \
  1715. .dma_boundary = ATA_DMA_BOUNDARY
  1716. extern enum ata_completion_errors ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
  1717. extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
  1718. extern enum ata_completion_errors ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
  1719. extern unsigned int ata_bmdma_port_intr(struct ata_port *ap,
  1720. struct ata_queued_cmd *qc);
  1721. extern irqreturn_t ata_bmdma_interrupt(int irq, void *dev_instance);
  1722. extern void ata_bmdma_error_handler(struct ata_port *ap);
  1723. extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
  1724. extern void ata_bmdma_irq_clear(struct ata_port *ap);
  1725. extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
  1726. extern void ata_bmdma_start(struct ata_queued_cmd *qc);
  1727. extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
  1728. extern u8 ata_bmdma_status(struct ata_port *ap);
  1729. extern int ata_bmdma_port_start(struct ata_port *ap);
  1730. extern int ata_bmdma_port_start32(struct ata_port *ap);
  1731. #ifdef CONFIG_PCI
  1732. extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
  1733. extern void ata_pci_bmdma_init(struct ata_host *host);
  1734. extern int ata_pci_bmdma_prepare_host(struct pci_dev *pdev,
  1735. const struct ata_port_info * const * ppi,
  1736. struct ata_host **r_host);
  1737. extern int ata_pci_bmdma_init_one(struct pci_dev *pdev,
  1738. const struct ata_port_info * const * ppi,
  1739. struct scsi_host_template *sht,
  1740. void *host_priv, int hflags);
  1741. #endif /* CONFIG_PCI */
  1742. #endif /* CONFIG_ATA_BMDMA */
  1743. /**
  1744. * ata_sff_busy_wait - Wait for a port status register
  1745. * @ap: Port to wait for.
  1746. * @bits: bits that must be clear
  1747. * @max: number of 10uS waits to perform
  1748. *
  1749. * Waits up to max*10 microseconds for the selected bits in the port's
  1750. * status register to be cleared.
  1751. * Returns final value of status register.
  1752. *
  1753. * LOCKING:
  1754. * Inherited from caller.
  1755. */
  1756. static inline u8 ata_sff_busy_wait(struct ata_port *ap, unsigned int bits,
  1757. unsigned int max)
  1758. {
  1759. u8 status;
  1760. do {
  1761. udelay(10);
  1762. status = ap->ops->sff_check_status(ap);
  1763. max--;
  1764. } while (status != 0xff && (status & bits) && (max > 0));
  1765. return status;
  1766. }
  1767. /**
  1768. * ata_wait_idle - Wait for a port to be idle.
  1769. * @ap: Port to wait for.
  1770. *
  1771. * Waits up to 10ms for port's BUSY and DRQ signals to clear.
  1772. * Returns final value of status register.
  1773. *
  1774. * LOCKING:
  1775. * Inherited from caller.
  1776. */
  1777. static inline u8 ata_wait_idle(struct ata_port *ap)
  1778. {
  1779. u8 status = ata_sff_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
  1780. if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ)))
  1781. ata_port_dbg(ap, "abnormal Status 0x%X\n", status);
  1782. return status;
  1783. }
  1784. #endif /* CONFIG_ATA_SFF */
  1785. #endif /* __LINUX_LIBATA_H__ */