sata_mv.c 88 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240
  1. /*
  2. * sata_mv.c - Marvell SATA support
  3. *
  4. * Copyright 2008: Marvell Corporation, all rights reserved.
  5. * Copyright 2005: EMC Corporation, all rights reserved.
  6. * Copyright 2005 Red Hat, Inc. All rights reserved.
  7. *
  8. * Please ALWAYS copy linux-ide@vger.kernel.org on emails.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; version 2 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. /*
  25. * sata_mv TODO list:
  26. *
  27. * --> Errata workaround for NCQ device errors.
  28. *
  29. * --> More errata workarounds for PCI-X.
  30. *
  31. * --> Complete a full errata audit for all chipsets to identify others.
  32. *
  33. * --> ATAPI support (Marvell claims the 60xx/70xx chips can do it).
  34. *
  35. * --> Investigate problems with PCI Message Signalled Interrupts (MSI).
  36. *
  37. * --> Cache frequently-accessed registers in mv_port_priv to reduce overhead.
  38. *
  39. * --> Develop a low-power-consumption strategy, and implement it.
  40. *
  41. * --> [Experiment, low priority] Investigate interrupt coalescing.
  42. * Quite often, especially with PCI Message Signalled Interrupts (MSI),
  43. * the overhead reduced by interrupt mitigation is quite often not
  44. * worth the latency cost.
  45. *
  46. * --> [Experiment, Marvell value added] Is it possible to use target
  47. * mode to cross-connect two Linux boxes with Marvell cards? If so,
  48. * creating LibATA target mode support would be very interesting.
  49. *
  50. * Target mode, for those without docs, is the ability to directly
  51. * connect two SATA ports.
  52. */
  53. #include <linux/kernel.h>
  54. #include <linux/module.h>
  55. #include <linux/pci.h>
  56. #include <linux/init.h>
  57. #include <linux/blkdev.h>
  58. #include <linux/delay.h>
  59. #include <linux/interrupt.h>
  60. #include <linux/dmapool.h>
  61. #include <linux/dma-mapping.h>
  62. #include <linux/device.h>
  63. #include <linux/platform_device.h>
  64. #include <linux/ata_platform.h>
  65. #include <linux/mbus.h>
  66. #include <scsi/scsi_host.h>
  67. #include <scsi/scsi_cmnd.h>
  68. #include <scsi/scsi_device.h>
  69. #include <linux/libata.h>
  70. #define DRV_NAME "sata_mv"
  71. #define DRV_VERSION "1.20"
  72. enum {
  73. /* BAR's are enumerated in terms of pci_resource_start() terms */
  74. MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */
  75. MV_IO_BAR = 2, /* offset 0x18: IO space */
  76. MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */
  77. MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
  78. MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
  79. MV_PCI_REG_BASE = 0,
  80. MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */
  81. MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08),
  82. MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88),
  83. MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c),
  84. MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc),
  85. MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0),
  86. MV_SATAHC0_REG_BASE = 0x20000,
  87. MV_FLASH_CTL_OFS = 0x1046c,
  88. MV_GPIO_PORT_CTL_OFS = 0x104f0,
  89. MV_RESET_CFG_OFS = 0x180d8,
  90. MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ,
  91. MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ,
  92. MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
  93. MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
  94. MV_MAX_Q_DEPTH = 32,
  95. MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
  96. /* CRQB needs alignment on a 1KB boundary. Size == 1KB
  97. * CRPB needs alignment on a 256B boundary. Size == 256B
  98. * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B
  99. */
  100. MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH),
  101. MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH),
  102. MV_MAX_SG_CT = 256,
  103. MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
  104. /* Determine hc from 0-7 port: hc = port >> MV_PORT_HC_SHIFT */
  105. MV_PORT_HC_SHIFT = 2,
  106. MV_PORTS_PER_HC = (1 << MV_PORT_HC_SHIFT), /* 4 */
  107. /* Determine hc port from 0-7 port: hardport = port & MV_PORT_MASK */
  108. MV_PORT_MASK = (MV_PORTS_PER_HC - 1), /* 3 */
  109. /* Host Flags */
  110. MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
  111. MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
  112. /* SoC integrated controllers, no PCI interface */
  113. MV_FLAG_SOC = (1 << 28),
  114. MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  115. ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
  116. ATA_FLAG_PIO_POLLING,
  117. MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
  118. CRQB_FLAG_READ = (1 << 0),
  119. CRQB_TAG_SHIFT = 1,
  120. CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */
  121. CRQB_PMP_SHIFT = 12, /* CRQB Gen-II/IIE PMP shift */
  122. CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */
  123. CRQB_CMD_ADDR_SHIFT = 8,
  124. CRQB_CMD_CS = (0x2 << 11),
  125. CRQB_CMD_LAST = (1 << 15),
  126. CRPB_FLAG_STATUS_SHIFT = 8,
  127. CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */
  128. CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */
  129. EPRD_FLAG_END_OF_TBL = (1 << 31),
  130. /* PCI interface registers */
  131. PCI_COMMAND_OFS = 0xc00,
  132. PCI_COMMAND_MRDTRIG = (1 << 7), /* PCI Master Read Trigger */
  133. PCI_MAIN_CMD_STS_OFS = 0xd30,
  134. STOP_PCI_MASTER = (1 << 2),
  135. PCI_MASTER_EMPTY = (1 << 3),
  136. GLOB_SFT_RST = (1 << 4),
  137. MV_PCI_MODE_OFS = 0xd00,
  138. MV_PCI_MODE_MASK = 0x30,
  139. MV_PCI_EXP_ROM_BAR_CTL = 0xd2c,
  140. MV_PCI_DISC_TIMER = 0xd04,
  141. MV_PCI_MSI_TRIGGER = 0xc38,
  142. MV_PCI_SERR_MASK = 0xc28,
  143. MV_PCI_XBAR_TMOUT_OFS = 0x1d04,
  144. MV_PCI_ERR_LOW_ADDRESS = 0x1d40,
  145. MV_PCI_ERR_HIGH_ADDRESS = 0x1d44,
  146. MV_PCI_ERR_ATTRIBUTE = 0x1d48,
  147. MV_PCI_ERR_COMMAND = 0x1d50,
  148. PCI_IRQ_CAUSE_OFS = 0x1d58,
  149. PCI_IRQ_MASK_OFS = 0x1d5c,
  150. PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
  151. PCIE_IRQ_CAUSE_OFS = 0x1900,
  152. PCIE_IRQ_MASK_OFS = 0x1910,
  153. PCIE_UNMASK_ALL_IRQS = 0x40a, /* assorted bits */
  154. /* Host Controller Main Interrupt Cause/Mask registers (1 per-chip) */
  155. PCI_HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
  156. PCI_HC_MAIN_IRQ_MASK_OFS = 0x1d64,
  157. SOC_HC_MAIN_IRQ_CAUSE_OFS = 0x20020,
  158. SOC_HC_MAIN_IRQ_MASK_OFS = 0x20024,
  159. ERR_IRQ = (1 << 0), /* shift by port # */
  160. DONE_IRQ = (1 << 1), /* shift by port # */
  161. HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
  162. HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
  163. PCI_ERR = (1 << 18),
  164. TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
  165. TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
  166. PORTS_0_3_COAL_DONE = (1 << 8),
  167. PORTS_4_7_COAL_DONE = (1 << 17),
  168. PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
  169. GPIO_INT = (1 << 22),
  170. SELF_INT = (1 << 23),
  171. TWSI_INT = (1 << 24),
  172. HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
  173. HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */
  174. HC_MAIN_RSVD_SOC = (0x3fffffb << 6), /* bits 31-9, 7-6 */
  175. HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
  176. PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
  177. PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
  178. HC_MAIN_RSVD),
  179. HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
  180. HC_MAIN_RSVD_5),
  181. HC_MAIN_MASKED_IRQS_SOC = (PORTS_0_3_COAL_DONE | HC_MAIN_RSVD_SOC),
  182. /* SATAHC registers */
  183. HC_CFG_OFS = 0,
  184. HC_IRQ_CAUSE_OFS = 0x14,
  185. DMA_IRQ = (1 << 0), /* shift by port # */
  186. HC_COAL_IRQ = (1 << 4), /* IRQ coalescing */
  187. DEV_IRQ = (1 << 8), /* shift by port # */
  188. /* Shadow block registers */
  189. SHD_BLK_OFS = 0x100,
  190. SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
  191. /* SATA registers */
  192. SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
  193. SATA_ACTIVE_OFS = 0x350,
  194. SATA_FIS_IRQ_CAUSE_OFS = 0x364,
  195. LTMODE_OFS = 0x30c,
  196. LTMODE_BIT8 = (1 << 8), /* unknown, but necessary */
  197. PHY_MODE3 = 0x310,
  198. PHY_MODE4 = 0x314,
  199. PHY_MODE2 = 0x330,
  200. SATA_IFCTL_OFS = 0x344,
  201. SATA_TESTCTL_OFS = 0x348,
  202. SATA_IFSTAT_OFS = 0x34c,
  203. VENDOR_UNIQUE_FIS_OFS = 0x35c,
  204. FISCFG_OFS = 0x360,
  205. FISCFG_WAIT_DEV_ERR = (1 << 8), /* wait for host on DevErr */
  206. FISCFG_SINGLE_SYNC = (1 << 16), /* SYNC on DMA activation */
  207. MV5_PHY_MODE = 0x74,
  208. MV5_LTMODE_OFS = 0x30,
  209. MV5_PHY_CTL_OFS = 0x0C,
  210. SATA_INTERFACE_CFG_OFS = 0x050,
  211. MV_M2_PREAMP_MASK = 0x7e0,
  212. /* Port registers */
  213. EDMA_CFG_OFS = 0,
  214. EDMA_CFG_Q_DEPTH = 0x1f, /* max device queue depth */
  215. EDMA_CFG_NCQ = (1 << 5), /* for R/W FPDMA queued */
  216. EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
  217. EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
  218. EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
  219. EDMA_CFG_EDMA_FBS = (1 << 16), /* EDMA FIS-Based Switching */
  220. EDMA_CFG_FBS = (1 << 26), /* FIS-Based Switching */
  221. EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
  222. EDMA_ERR_IRQ_MASK_OFS = 0xc,
  223. EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */
  224. EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */
  225. EDMA_ERR_DEV = (1 << 2), /* device error */
  226. EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */
  227. EDMA_ERR_DEV_CON = (1 << 4), /* device connected */
  228. EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */
  229. EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */
  230. EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */
  231. EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */
  232. EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */
  233. EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */
  234. EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */
  235. EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */
  236. EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */
  237. EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */
  238. EDMA_ERR_LNK_CTRL_RX_0 = (1 << 13), /* transient: CRC err */
  239. EDMA_ERR_LNK_CTRL_RX_1 = (1 << 14), /* transient: FIFO err */
  240. EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), /* fatal: caught SYNC */
  241. EDMA_ERR_LNK_CTRL_RX_3 = (1 << 16), /* transient: FIS rx err */
  242. EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */
  243. EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */
  244. EDMA_ERR_LNK_CTRL_TX_0 = (1 << 21), /* transient: CRC err */
  245. EDMA_ERR_LNK_CTRL_TX_1 = (1 << 22), /* transient: FIFO err */
  246. EDMA_ERR_LNK_CTRL_TX_2 = (1 << 23), /* transient: caught SYNC */
  247. EDMA_ERR_LNK_CTRL_TX_3 = (1 << 24), /* transient: caught DMAT */
  248. EDMA_ERR_LNK_CTRL_TX_4 = (1 << 25), /* transient: FIS collision */
  249. EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */
  250. EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */
  251. EDMA_ERR_OVERRUN_5 = (1 << 5),
  252. EDMA_ERR_UNDERRUN_5 = (1 << 6),
  253. EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 |
  254. EDMA_ERR_LNK_CTRL_RX_1 |
  255. EDMA_ERR_LNK_CTRL_RX_3 |
  256. EDMA_ERR_LNK_CTRL_TX,
  257. EDMA_EH_FREEZE = EDMA_ERR_D_PAR |
  258. EDMA_ERR_PRD_PAR |
  259. EDMA_ERR_DEV_DCON |
  260. EDMA_ERR_DEV_CON |
  261. EDMA_ERR_SERR |
  262. EDMA_ERR_SELF_DIS |
  263. EDMA_ERR_CRQB_PAR |
  264. EDMA_ERR_CRPB_PAR |
  265. EDMA_ERR_INTRL_PAR |
  266. EDMA_ERR_IORDY |
  267. EDMA_ERR_LNK_CTRL_RX_2 |
  268. EDMA_ERR_LNK_DATA_RX |
  269. EDMA_ERR_LNK_DATA_TX |
  270. EDMA_ERR_TRANS_PROTO,
  271. EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR |
  272. EDMA_ERR_PRD_PAR |
  273. EDMA_ERR_DEV_DCON |
  274. EDMA_ERR_DEV_CON |
  275. EDMA_ERR_OVERRUN_5 |
  276. EDMA_ERR_UNDERRUN_5 |
  277. EDMA_ERR_SELF_DIS_5 |
  278. EDMA_ERR_CRQB_PAR |
  279. EDMA_ERR_CRPB_PAR |
  280. EDMA_ERR_INTRL_PAR |
  281. EDMA_ERR_IORDY,
  282. EDMA_REQ_Q_BASE_HI_OFS = 0x10,
  283. EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
  284. EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
  285. EDMA_REQ_Q_PTR_SHIFT = 5,
  286. EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
  287. EDMA_RSP_Q_IN_PTR_OFS = 0x20,
  288. EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
  289. EDMA_RSP_Q_PTR_SHIFT = 3,
  290. EDMA_CMD_OFS = 0x28, /* EDMA command register */
  291. EDMA_EN = (1 << 0), /* enable EDMA */
  292. EDMA_DS = (1 << 1), /* disable EDMA; self-negated */
  293. EDMA_RESET = (1 << 2), /* reset eng/trans/link/phy */
  294. EDMA_STATUS_OFS = 0x30, /* EDMA engine status */
  295. EDMA_STATUS_CACHE_EMPTY = (1 << 6), /* GenIIe command cache empty */
  296. EDMA_STATUS_IDLE = (1 << 7), /* GenIIe EDMA enabled/idle */
  297. EDMA_IORDY_TMOUT_OFS = 0x34,
  298. EDMA_ARB_CFG_OFS = 0x38,
  299. EDMA_HALTCOND_OFS = 0x60, /* GenIIe halt conditions */
  300. GEN_II_NCQ_MAX_SECTORS = 256, /* max sects/io on Gen2 w/NCQ */
  301. /* Host private flags (hp_flags) */
  302. MV_HP_FLAG_MSI = (1 << 0),
  303. MV_HP_ERRATA_50XXB0 = (1 << 1),
  304. MV_HP_ERRATA_50XXB2 = (1 << 2),
  305. MV_HP_ERRATA_60X1B2 = (1 << 3),
  306. MV_HP_ERRATA_60X1C0 = (1 << 4),
  307. MV_HP_ERRATA_XX42A0 = (1 << 5),
  308. MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */
  309. MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */
  310. MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */
  311. MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */
  312. MV_HP_CUT_THROUGH = (1 << 10), /* can use EDMA cut-through */
  313. /* Port private flags (pp_flags) */
  314. MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
  315. MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */
  316. MV_PP_FLAG_FBS_EN = (1 << 2), /* is EDMA set up for FBS? */
  317. };
  318. #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I)
  319. #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II)
  320. #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
  321. #define IS_PCIE(hpriv) ((hpriv)->hp_flags & MV_HP_PCIE)
  322. #define HAS_PCI(host) (!((host)->ports[0]->flags & MV_FLAG_SOC))
  323. #define WINDOW_CTRL(i) (0x20030 + ((i) << 4))
  324. #define WINDOW_BASE(i) (0x20034 + ((i) << 4))
  325. enum {
  326. /* DMA boundary 0xffff is required by the s/g splitting
  327. * we need on /length/ in mv_fill-sg().
  328. */
  329. MV_DMA_BOUNDARY = 0xffffU,
  330. /* mask of register bits containing lower 32 bits
  331. * of EDMA request queue DMA address
  332. */
  333. EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
  334. /* ditto, for response queue */
  335. EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
  336. };
  337. enum chip_type {
  338. chip_504x,
  339. chip_508x,
  340. chip_5080,
  341. chip_604x,
  342. chip_608x,
  343. chip_6042,
  344. chip_7042,
  345. chip_soc,
  346. };
  347. /* Command ReQuest Block: 32B */
  348. struct mv_crqb {
  349. __le32 sg_addr;
  350. __le32 sg_addr_hi;
  351. __le16 ctrl_flags;
  352. __le16 ata_cmd[11];
  353. };
  354. struct mv_crqb_iie {
  355. __le32 addr;
  356. __le32 addr_hi;
  357. __le32 flags;
  358. __le32 len;
  359. __le32 ata_cmd[4];
  360. };
  361. /* Command ResPonse Block: 8B */
  362. struct mv_crpb {
  363. __le16 id;
  364. __le16 flags;
  365. __le32 tmstmp;
  366. };
  367. /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
  368. struct mv_sg {
  369. __le32 addr;
  370. __le32 flags_size;
  371. __le32 addr_hi;
  372. __le32 reserved;
  373. };
  374. struct mv_port_priv {
  375. struct mv_crqb *crqb;
  376. dma_addr_t crqb_dma;
  377. struct mv_crpb *crpb;
  378. dma_addr_t crpb_dma;
  379. struct mv_sg *sg_tbl[MV_MAX_Q_DEPTH];
  380. dma_addr_t sg_tbl_dma[MV_MAX_Q_DEPTH];
  381. unsigned int req_idx;
  382. unsigned int resp_idx;
  383. u32 pp_flags;
  384. };
  385. struct mv_port_signal {
  386. u32 amps;
  387. u32 pre;
  388. };
  389. struct mv_host_priv {
  390. u32 hp_flags;
  391. struct mv_port_signal signal[8];
  392. const struct mv_hw_ops *ops;
  393. int n_ports;
  394. void __iomem *base;
  395. void __iomem *main_irq_cause_addr;
  396. void __iomem *main_irq_mask_addr;
  397. u32 irq_cause_ofs;
  398. u32 irq_mask_ofs;
  399. u32 unmask_all_irqs;
  400. /*
  401. * These consistent DMA memory pools give us guaranteed
  402. * alignment for hardware-accessed data structures,
  403. * and less memory waste in accomplishing the alignment.
  404. */
  405. struct dma_pool *crqb_pool;
  406. struct dma_pool *crpb_pool;
  407. struct dma_pool *sg_tbl_pool;
  408. };
  409. struct mv_hw_ops {
  410. void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
  411. unsigned int port);
  412. void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio);
  413. void (*read_preamp)(struct mv_host_priv *hpriv, int idx,
  414. void __iomem *mmio);
  415. int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio,
  416. unsigned int n_hc);
  417. void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio);
  418. void (*reset_bus)(struct ata_host *host, void __iomem *mmio);
  419. };
  420. static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
  421. static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
  422. static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
  423. static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
  424. static int mv_port_start(struct ata_port *ap);
  425. static void mv_port_stop(struct ata_port *ap);
  426. static int mv_qc_defer(struct ata_queued_cmd *qc);
  427. static void mv_qc_prep(struct ata_queued_cmd *qc);
  428. static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
  429. static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
  430. static int mv_hardreset(struct ata_link *link, unsigned int *class,
  431. unsigned long deadline);
  432. static void mv_eh_freeze(struct ata_port *ap);
  433. static void mv_eh_thaw(struct ata_port *ap);
  434. static void mv6_dev_config(struct ata_device *dev);
  435. static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  436. unsigned int port);
  437. static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
  438. static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
  439. void __iomem *mmio);
  440. static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  441. unsigned int n_hc);
  442. static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
  443. static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio);
  444. static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  445. unsigned int port);
  446. static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
  447. static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
  448. void __iomem *mmio);
  449. static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  450. unsigned int n_hc);
  451. static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
  452. static void mv_soc_enable_leds(struct mv_host_priv *hpriv,
  453. void __iomem *mmio);
  454. static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx,
  455. void __iomem *mmio);
  456. static int mv_soc_reset_hc(struct mv_host_priv *hpriv,
  457. void __iomem *mmio, unsigned int n_hc);
  458. static void mv_soc_reset_flash(struct mv_host_priv *hpriv,
  459. void __iomem *mmio);
  460. static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio);
  461. static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio);
  462. static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio,
  463. unsigned int port_no);
  464. static int mv_stop_edma(struct ata_port *ap);
  465. static int mv_stop_edma_engine(void __iomem *port_mmio);
  466. static void mv_edma_cfg(struct ata_port *ap, int want_ncq);
  467. static void mv_pmp_select(struct ata_port *ap, int pmp);
  468. static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class,
  469. unsigned long deadline);
  470. static int mv_softreset(struct ata_link *link, unsigned int *class,
  471. unsigned long deadline);
  472. /* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below
  473. * because we have to allow room for worst case splitting of
  474. * PRDs for 64K boundaries in mv_fill_sg().
  475. */
  476. static struct scsi_host_template mv5_sht = {
  477. ATA_BASE_SHT(DRV_NAME),
  478. .sg_tablesize = MV_MAX_SG_CT / 2,
  479. .dma_boundary = MV_DMA_BOUNDARY,
  480. };
  481. static struct scsi_host_template mv6_sht = {
  482. ATA_NCQ_SHT(DRV_NAME),
  483. .can_queue = MV_MAX_Q_DEPTH - 1,
  484. .sg_tablesize = MV_MAX_SG_CT / 2,
  485. .dma_boundary = MV_DMA_BOUNDARY,
  486. };
  487. static struct ata_port_operations mv5_ops = {
  488. .inherits = &ata_sff_port_ops,
  489. .qc_defer = mv_qc_defer,
  490. .qc_prep = mv_qc_prep,
  491. .qc_issue = mv_qc_issue,
  492. .freeze = mv_eh_freeze,
  493. .thaw = mv_eh_thaw,
  494. .hardreset = mv_hardreset,
  495. .error_handler = ata_std_error_handler, /* avoid SFF EH */
  496. .post_internal_cmd = ATA_OP_NULL,
  497. .scr_read = mv5_scr_read,
  498. .scr_write = mv5_scr_write,
  499. .port_start = mv_port_start,
  500. .port_stop = mv_port_stop,
  501. };
  502. static struct ata_port_operations mv6_ops = {
  503. .inherits = &mv5_ops,
  504. .dev_config = mv6_dev_config,
  505. .scr_read = mv_scr_read,
  506. .scr_write = mv_scr_write,
  507. .pmp_hardreset = mv_pmp_hardreset,
  508. .pmp_softreset = mv_softreset,
  509. .softreset = mv_softreset,
  510. .error_handler = sata_pmp_error_handler,
  511. };
  512. static struct ata_port_operations mv_iie_ops = {
  513. .inherits = &mv6_ops,
  514. .dev_config = ATA_OP_NULL,
  515. .qc_prep = mv_qc_prep_iie,
  516. };
  517. static const struct ata_port_info mv_port_info[] = {
  518. { /* chip_504x */
  519. .flags = MV_COMMON_FLAGS,
  520. .pio_mask = 0x1f, /* pio0-4 */
  521. .udma_mask = ATA_UDMA6,
  522. .port_ops = &mv5_ops,
  523. },
  524. { /* chip_508x */
  525. .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
  526. .pio_mask = 0x1f, /* pio0-4 */
  527. .udma_mask = ATA_UDMA6,
  528. .port_ops = &mv5_ops,
  529. },
  530. { /* chip_5080 */
  531. .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
  532. .pio_mask = 0x1f, /* pio0-4 */
  533. .udma_mask = ATA_UDMA6,
  534. .port_ops = &mv5_ops,
  535. },
  536. { /* chip_604x */
  537. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  538. ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
  539. ATA_FLAG_NCQ,
  540. .pio_mask = 0x1f, /* pio0-4 */
  541. .udma_mask = ATA_UDMA6,
  542. .port_ops = &mv6_ops,
  543. },
  544. { /* chip_608x */
  545. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  546. ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
  547. ATA_FLAG_NCQ | MV_FLAG_DUAL_HC,
  548. .pio_mask = 0x1f, /* pio0-4 */
  549. .udma_mask = ATA_UDMA6,
  550. .port_ops = &mv6_ops,
  551. },
  552. { /* chip_6042 */
  553. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  554. ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
  555. ATA_FLAG_NCQ,
  556. .pio_mask = 0x1f, /* pio0-4 */
  557. .udma_mask = ATA_UDMA6,
  558. .port_ops = &mv_iie_ops,
  559. },
  560. { /* chip_7042 */
  561. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  562. ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
  563. ATA_FLAG_NCQ,
  564. .pio_mask = 0x1f, /* pio0-4 */
  565. .udma_mask = ATA_UDMA6,
  566. .port_ops = &mv_iie_ops,
  567. },
  568. { /* chip_soc */
  569. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  570. ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
  571. ATA_FLAG_NCQ | MV_FLAG_SOC,
  572. .pio_mask = 0x1f, /* pio0-4 */
  573. .udma_mask = ATA_UDMA6,
  574. .port_ops = &mv_iie_ops,
  575. },
  576. };
  577. static const struct pci_device_id mv_pci_tbl[] = {
  578. { PCI_VDEVICE(MARVELL, 0x5040), chip_504x },
  579. { PCI_VDEVICE(MARVELL, 0x5041), chip_504x },
  580. { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 },
  581. { PCI_VDEVICE(MARVELL, 0x5081), chip_508x },
  582. /* RocketRAID 1740/174x have different identifiers */
  583. { PCI_VDEVICE(TTI, 0x1740), chip_508x },
  584. { PCI_VDEVICE(TTI, 0x1742), chip_508x },
  585. { PCI_VDEVICE(MARVELL, 0x6040), chip_604x },
  586. { PCI_VDEVICE(MARVELL, 0x6041), chip_604x },
  587. { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 },
  588. { PCI_VDEVICE(MARVELL, 0x6080), chip_608x },
  589. { PCI_VDEVICE(MARVELL, 0x6081), chip_608x },
  590. { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x },
  591. /* Adaptec 1430SA */
  592. { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 },
  593. /* Marvell 7042 support */
  594. { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 },
  595. /* Highpoint RocketRAID PCIe series */
  596. { PCI_VDEVICE(TTI, 0x2300), chip_7042 },
  597. { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
  598. { } /* terminate list */
  599. };
  600. static const struct mv_hw_ops mv5xxx_ops = {
  601. .phy_errata = mv5_phy_errata,
  602. .enable_leds = mv5_enable_leds,
  603. .read_preamp = mv5_read_preamp,
  604. .reset_hc = mv5_reset_hc,
  605. .reset_flash = mv5_reset_flash,
  606. .reset_bus = mv5_reset_bus,
  607. };
  608. static const struct mv_hw_ops mv6xxx_ops = {
  609. .phy_errata = mv6_phy_errata,
  610. .enable_leds = mv6_enable_leds,
  611. .read_preamp = mv6_read_preamp,
  612. .reset_hc = mv6_reset_hc,
  613. .reset_flash = mv6_reset_flash,
  614. .reset_bus = mv_reset_pci_bus,
  615. };
  616. static const struct mv_hw_ops mv_soc_ops = {
  617. .phy_errata = mv6_phy_errata,
  618. .enable_leds = mv_soc_enable_leds,
  619. .read_preamp = mv_soc_read_preamp,
  620. .reset_hc = mv_soc_reset_hc,
  621. .reset_flash = mv_soc_reset_flash,
  622. .reset_bus = mv_soc_reset_bus,
  623. };
  624. /*
  625. * Functions
  626. */
  627. static inline void writelfl(unsigned long data, void __iomem *addr)
  628. {
  629. writel(data, addr);
  630. (void) readl(addr); /* flush to avoid PCI posted write */
  631. }
  632. static inline unsigned int mv_hc_from_port(unsigned int port)
  633. {
  634. return port >> MV_PORT_HC_SHIFT;
  635. }
  636. static inline unsigned int mv_hardport_from_port(unsigned int port)
  637. {
  638. return port & MV_PORT_MASK;
  639. }
  640. /*
  641. * Consolidate some rather tricky bit shift calculations.
  642. * This is hot-path stuff, so not a function.
  643. * Simple code, with two return values, so macro rather than inline.
  644. *
  645. * port is the sole input, in range 0..7.
  646. * shift is one output, for use with main_irq_cause / main_irq_mask registers.
  647. * hardport is the other output, in range 0..3.
  648. *
  649. * Note that port and hardport may be the same variable in some cases.
  650. */
  651. #define MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport) \
  652. { \
  653. shift = mv_hc_from_port(port) * HC_SHIFT; \
  654. hardport = mv_hardport_from_port(port); \
  655. shift += hardport * 2; \
  656. }
  657. static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
  658. {
  659. return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
  660. }
  661. static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
  662. unsigned int port)
  663. {
  664. return mv_hc_base(base, mv_hc_from_port(port));
  665. }
  666. static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
  667. {
  668. return mv_hc_base_from_port(base, port) +
  669. MV_SATAHC_ARBTR_REG_SZ +
  670. (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
  671. }
  672. static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port)
  673. {
  674. void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port);
  675. unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL;
  676. return hc_mmio + ofs;
  677. }
  678. static inline void __iomem *mv_host_base(struct ata_host *host)
  679. {
  680. struct mv_host_priv *hpriv = host->private_data;
  681. return hpriv->base;
  682. }
  683. static inline void __iomem *mv_ap_base(struct ata_port *ap)
  684. {
  685. return mv_port_base(mv_host_base(ap->host), ap->port_no);
  686. }
  687. static inline int mv_get_hc_count(unsigned long port_flags)
  688. {
  689. return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
  690. }
  691. static void mv_set_edma_ptrs(void __iomem *port_mmio,
  692. struct mv_host_priv *hpriv,
  693. struct mv_port_priv *pp)
  694. {
  695. u32 index;
  696. /*
  697. * initialize request queue
  698. */
  699. pp->req_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */
  700. index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
  701. WARN_ON(pp->crqb_dma & 0x3ff);
  702. writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
  703. writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index,
  704. port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
  705. if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
  706. writelfl((pp->crqb_dma & 0xffffffff) | index,
  707. port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
  708. else
  709. writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
  710. /*
  711. * initialize response queue
  712. */
  713. pp->resp_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */
  714. index = pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT;
  715. WARN_ON(pp->crpb_dma & 0xff);
  716. writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
  717. if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
  718. writelfl((pp->crpb_dma & 0xffffffff) | index,
  719. port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
  720. else
  721. writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
  722. writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index,
  723. port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  724. }
  725. /**
  726. * mv_start_dma - Enable eDMA engine
  727. * @base: port base address
  728. * @pp: port private data
  729. *
  730. * Verify the local cache of the eDMA state is accurate with a
  731. * WARN_ON.
  732. *
  733. * LOCKING:
  734. * Inherited from caller.
  735. */
  736. static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio,
  737. struct mv_port_priv *pp, u8 protocol)
  738. {
  739. int want_ncq = (protocol == ATA_PROT_NCQ);
  740. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
  741. int using_ncq = ((pp->pp_flags & MV_PP_FLAG_NCQ_EN) != 0);
  742. if (want_ncq != using_ncq)
  743. mv_stop_edma(ap);
  744. }
  745. if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
  746. struct mv_host_priv *hpriv = ap->host->private_data;
  747. int hardport = mv_hardport_from_port(ap->port_no);
  748. void __iomem *hc_mmio = mv_hc_base_from_port(
  749. mv_host_base(ap->host), hardport);
  750. u32 hc_irq_cause, ipending;
  751. /* clear EDMA event indicators, if any */
  752. writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  753. /* clear EDMA interrupt indicator, if any */
  754. hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
  755. ipending = (DEV_IRQ | DMA_IRQ) << hardport;
  756. if (hc_irq_cause & ipending) {
  757. writelfl(hc_irq_cause & ~ipending,
  758. hc_mmio + HC_IRQ_CAUSE_OFS);
  759. }
  760. mv_edma_cfg(ap, want_ncq);
  761. /* clear FIS IRQ Cause */
  762. writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS);
  763. mv_set_edma_ptrs(port_mmio, hpriv, pp);
  764. writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS);
  765. pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
  766. }
  767. }
  768. static void mv_wait_for_edma_empty_idle(struct ata_port *ap)
  769. {
  770. void __iomem *port_mmio = mv_ap_base(ap);
  771. const u32 empty_idle = (EDMA_STATUS_CACHE_EMPTY | EDMA_STATUS_IDLE);
  772. const int per_loop = 5, timeout = (15 * 1000 / per_loop);
  773. int i;
  774. /*
  775. * Wait for the EDMA engine to finish transactions in progress.
  776. */
  777. for (i = 0; i < timeout; ++i) {
  778. u32 edma_stat = readl(port_mmio + EDMA_STATUS_OFS);
  779. if ((edma_stat & empty_idle) == empty_idle)
  780. break;
  781. udelay(per_loop);
  782. }
  783. /* ata_port_printk(ap, KERN_INFO, "%s: %u+ usecs\n", __func__, i); */
  784. }
  785. /**
  786. * mv_stop_edma_engine - Disable eDMA engine
  787. * @port_mmio: io base address
  788. *
  789. * LOCKING:
  790. * Inherited from caller.
  791. */
  792. static int mv_stop_edma_engine(void __iomem *port_mmio)
  793. {
  794. int i;
  795. /* Disable eDMA. The disable bit auto clears. */
  796. writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
  797. /* Wait for the chip to confirm eDMA is off. */
  798. for (i = 10000; i > 0; i--) {
  799. u32 reg = readl(port_mmio + EDMA_CMD_OFS);
  800. if (!(reg & EDMA_EN))
  801. return 0;
  802. udelay(10);
  803. }
  804. return -EIO;
  805. }
  806. static int mv_stop_edma(struct ata_port *ap)
  807. {
  808. void __iomem *port_mmio = mv_ap_base(ap);
  809. struct mv_port_priv *pp = ap->private_data;
  810. if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN))
  811. return 0;
  812. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  813. mv_wait_for_edma_empty_idle(ap);
  814. if (mv_stop_edma_engine(port_mmio)) {
  815. ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n");
  816. return -EIO;
  817. }
  818. return 0;
  819. }
  820. #ifdef ATA_DEBUG
  821. static void mv_dump_mem(void __iomem *start, unsigned bytes)
  822. {
  823. int b, w;
  824. for (b = 0; b < bytes; ) {
  825. DPRINTK("%p: ", start + b);
  826. for (w = 0; b < bytes && w < 4; w++) {
  827. printk("%08x ", readl(start + b));
  828. b += sizeof(u32);
  829. }
  830. printk("\n");
  831. }
  832. }
  833. #endif
  834. static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
  835. {
  836. #ifdef ATA_DEBUG
  837. int b, w;
  838. u32 dw;
  839. for (b = 0; b < bytes; ) {
  840. DPRINTK("%02x: ", b);
  841. for (w = 0; b < bytes && w < 4; w++) {
  842. (void) pci_read_config_dword(pdev, b, &dw);
  843. printk("%08x ", dw);
  844. b += sizeof(u32);
  845. }
  846. printk("\n");
  847. }
  848. #endif
  849. }
  850. static void mv_dump_all_regs(void __iomem *mmio_base, int port,
  851. struct pci_dev *pdev)
  852. {
  853. #ifdef ATA_DEBUG
  854. void __iomem *hc_base = mv_hc_base(mmio_base,
  855. port >> MV_PORT_HC_SHIFT);
  856. void __iomem *port_base;
  857. int start_port, num_ports, p, start_hc, num_hcs, hc;
  858. if (0 > port) {
  859. start_hc = start_port = 0;
  860. num_ports = 8; /* shld be benign for 4 port devs */
  861. num_hcs = 2;
  862. } else {
  863. start_hc = port >> MV_PORT_HC_SHIFT;
  864. start_port = port;
  865. num_ports = num_hcs = 1;
  866. }
  867. DPRINTK("All registers for port(s) %u-%u:\n", start_port,
  868. num_ports > 1 ? num_ports - 1 : start_port);
  869. if (NULL != pdev) {
  870. DPRINTK("PCI config space regs:\n");
  871. mv_dump_pci_cfg(pdev, 0x68);
  872. }
  873. DPRINTK("PCI regs:\n");
  874. mv_dump_mem(mmio_base+0xc00, 0x3c);
  875. mv_dump_mem(mmio_base+0xd00, 0x34);
  876. mv_dump_mem(mmio_base+0xf00, 0x4);
  877. mv_dump_mem(mmio_base+0x1d00, 0x6c);
  878. for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
  879. hc_base = mv_hc_base(mmio_base, hc);
  880. DPRINTK("HC regs (HC %i):\n", hc);
  881. mv_dump_mem(hc_base, 0x1c);
  882. }
  883. for (p = start_port; p < start_port + num_ports; p++) {
  884. port_base = mv_port_base(mmio_base, p);
  885. DPRINTK("EDMA regs (port %i):\n", p);
  886. mv_dump_mem(port_base, 0x54);
  887. DPRINTK("SATA regs (port %i):\n", p);
  888. mv_dump_mem(port_base+0x300, 0x60);
  889. }
  890. #endif
  891. }
  892. static unsigned int mv_scr_offset(unsigned int sc_reg_in)
  893. {
  894. unsigned int ofs;
  895. switch (sc_reg_in) {
  896. case SCR_STATUS:
  897. case SCR_CONTROL:
  898. case SCR_ERROR:
  899. ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
  900. break;
  901. case SCR_ACTIVE:
  902. ofs = SATA_ACTIVE_OFS; /* active is not with the others */
  903. break;
  904. default:
  905. ofs = 0xffffffffU;
  906. break;
  907. }
  908. return ofs;
  909. }
  910. static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
  911. {
  912. unsigned int ofs = mv_scr_offset(sc_reg_in);
  913. if (ofs != 0xffffffffU) {
  914. *val = readl(mv_ap_base(ap) + ofs);
  915. return 0;
  916. } else
  917. return -EINVAL;
  918. }
  919. static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
  920. {
  921. unsigned int ofs = mv_scr_offset(sc_reg_in);
  922. if (ofs != 0xffffffffU) {
  923. writelfl(val, mv_ap_base(ap) + ofs);
  924. return 0;
  925. } else
  926. return -EINVAL;
  927. }
  928. static void mv6_dev_config(struct ata_device *adev)
  929. {
  930. /*
  931. * Deal with Gen-II ("mv6") hardware quirks/restrictions:
  932. *
  933. * Gen-II does not support NCQ over a port multiplier
  934. * (no FIS-based switching).
  935. *
  936. * We don't have hob_nsect when doing NCQ commands on Gen-II.
  937. * See mv_qc_prep() for more info.
  938. */
  939. if (adev->flags & ATA_DFLAG_NCQ) {
  940. if (sata_pmp_attached(adev->link->ap)) {
  941. adev->flags &= ~ATA_DFLAG_NCQ;
  942. ata_dev_printk(adev, KERN_INFO,
  943. "NCQ disabled for command-based switching\n");
  944. } else if (adev->max_sectors > GEN_II_NCQ_MAX_SECTORS) {
  945. adev->max_sectors = GEN_II_NCQ_MAX_SECTORS;
  946. ata_dev_printk(adev, KERN_INFO,
  947. "max_sectors limited to %u for NCQ\n",
  948. adev->max_sectors);
  949. }
  950. }
  951. }
  952. static int mv_qc_defer(struct ata_queued_cmd *qc)
  953. {
  954. struct ata_link *link = qc->dev->link;
  955. struct ata_port *ap = link->ap;
  956. struct mv_port_priv *pp = ap->private_data;
  957. /*
  958. * If the port is completely idle, then allow the new qc.
  959. */
  960. if (ap->nr_active_links == 0)
  961. return 0;
  962. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
  963. /*
  964. * The port is operating in host queuing mode (EDMA).
  965. * It can accomodate a new qc if the qc protocol
  966. * is compatible with the current host queue mode.
  967. */
  968. if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) {
  969. /*
  970. * The host queue (EDMA) is in NCQ mode.
  971. * If the new qc is also an NCQ command,
  972. * then allow the new qc.
  973. */
  974. if (qc->tf.protocol == ATA_PROT_NCQ)
  975. return 0;
  976. } else {
  977. /*
  978. * The host queue (EDMA) is in non-NCQ, DMA mode.
  979. * If the new qc is also a non-NCQ, DMA command,
  980. * then allow the new qc.
  981. */
  982. if (qc->tf.protocol == ATA_PROT_DMA)
  983. return 0;
  984. }
  985. }
  986. return ATA_DEFER_PORT;
  987. }
  988. static void mv_config_fbs(void __iomem *port_mmio, int want_ncq, int want_fbs)
  989. {
  990. u32 new_fiscfg, old_fiscfg;
  991. u32 new_ltmode, old_ltmode;
  992. u32 new_haltcond, old_haltcond;
  993. old_fiscfg = readl(port_mmio + FISCFG_OFS);
  994. old_ltmode = readl(port_mmio + LTMODE_OFS);
  995. old_haltcond = readl(port_mmio + EDMA_HALTCOND_OFS);
  996. new_fiscfg = old_fiscfg & ~(FISCFG_SINGLE_SYNC | FISCFG_WAIT_DEV_ERR);
  997. new_ltmode = old_ltmode & ~LTMODE_BIT8;
  998. new_haltcond = old_haltcond | EDMA_ERR_DEV;
  999. if (want_fbs) {
  1000. new_fiscfg = old_fiscfg | FISCFG_SINGLE_SYNC;
  1001. new_ltmode = old_ltmode | LTMODE_BIT8;
  1002. }
  1003. if (new_fiscfg != old_fiscfg)
  1004. writelfl(new_fiscfg, port_mmio + FISCFG_OFS);
  1005. if (new_ltmode != old_ltmode)
  1006. writelfl(new_ltmode, port_mmio + LTMODE_OFS);
  1007. if (new_haltcond != old_haltcond)
  1008. writelfl(new_haltcond, port_mmio + EDMA_HALTCOND_OFS);
  1009. }
  1010. static void mv_60x1_errata_sata25(struct ata_port *ap, int want_ncq)
  1011. {
  1012. struct mv_host_priv *hpriv = ap->host->private_data;
  1013. u32 old, new;
  1014. /* workaround for 88SX60x1 FEr SATA#25 (part 1) */
  1015. old = readl(hpriv->base + MV_GPIO_PORT_CTL_OFS);
  1016. if (want_ncq)
  1017. new = old | (1 << 22);
  1018. else
  1019. new = old & ~(1 << 22);
  1020. if (new != old)
  1021. writel(new, hpriv->base + MV_GPIO_PORT_CTL_OFS);
  1022. }
  1023. static void mv_edma_cfg(struct ata_port *ap, int want_ncq)
  1024. {
  1025. u32 cfg;
  1026. struct mv_port_priv *pp = ap->private_data;
  1027. struct mv_host_priv *hpriv = ap->host->private_data;
  1028. void __iomem *port_mmio = mv_ap_base(ap);
  1029. /* set up non-NCQ EDMA configuration */
  1030. cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */
  1031. pp->pp_flags &= ~MV_PP_FLAG_FBS_EN;
  1032. if (IS_GEN_I(hpriv))
  1033. cfg |= (1 << 8); /* enab config burst size mask */
  1034. else if (IS_GEN_II(hpriv)) {
  1035. cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN;
  1036. mv_60x1_errata_sata25(ap, want_ncq);
  1037. } else if (IS_GEN_IIE(hpriv)) {
  1038. int want_fbs = sata_pmp_attached(ap);
  1039. /*
  1040. * Possible future enhancement:
  1041. *
  1042. * The chip can use FBS with non-NCQ, if we allow it,
  1043. * But first we need to have the error handling in place
  1044. * for this mode (datasheet section 7.3.15.4.2.3).
  1045. * So disallow non-NCQ FBS for now.
  1046. */
  1047. want_fbs &= want_ncq;
  1048. mv_config_fbs(port_mmio, want_ncq, want_fbs);
  1049. if (want_fbs) {
  1050. pp->pp_flags |= MV_PP_FLAG_FBS_EN;
  1051. cfg |= EDMA_CFG_EDMA_FBS; /* FIS-based switching */
  1052. }
  1053. cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */
  1054. cfg |= (1 << 22); /* enab 4-entry host queue cache */
  1055. if (HAS_PCI(ap->host))
  1056. cfg |= (1 << 18); /* enab early completion */
  1057. if (hpriv->hp_flags & MV_HP_CUT_THROUGH)
  1058. cfg |= (1 << 17); /* enab cut-thru (dis stor&forwrd) */
  1059. }
  1060. if (want_ncq) {
  1061. cfg |= EDMA_CFG_NCQ;
  1062. pp->pp_flags |= MV_PP_FLAG_NCQ_EN;
  1063. } else
  1064. pp->pp_flags &= ~MV_PP_FLAG_NCQ_EN;
  1065. writelfl(cfg, port_mmio + EDMA_CFG_OFS);
  1066. }
  1067. static void mv_port_free_dma_mem(struct ata_port *ap)
  1068. {
  1069. struct mv_host_priv *hpriv = ap->host->private_data;
  1070. struct mv_port_priv *pp = ap->private_data;
  1071. int tag;
  1072. if (pp->crqb) {
  1073. dma_pool_free(hpriv->crqb_pool, pp->crqb, pp->crqb_dma);
  1074. pp->crqb = NULL;
  1075. }
  1076. if (pp->crpb) {
  1077. dma_pool_free(hpriv->crpb_pool, pp->crpb, pp->crpb_dma);
  1078. pp->crpb = NULL;
  1079. }
  1080. /*
  1081. * For GEN_I, there's no NCQ, so we have only a single sg_tbl.
  1082. * For later hardware, we have one unique sg_tbl per NCQ tag.
  1083. */
  1084. for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) {
  1085. if (pp->sg_tbl[tag]) {
  1086. if (tag == 0 || !IS_GEN_I(hpriv))
  1087. dma_pool_free(hpriv->sg_tbl_pool,
  1088. pp->sg_tbl[tag],
  1089. pp->sg_tbl_dma[tag]);
  1090. pp->sg_tbl[tag] = NULL;
  1091. }
  1092. }
  1093. }
  1094. /**
  1095. * mv_port_start - Port specific init/start routine.
  1096. * @ap: ATA channel to manipulate
  1097. *
  1098. * Allocate and point to DMA memory, init port private memory,
  1099. * zero indices.
  1100. *
  1101. * LOCKING:
  1102. * Inherited from caller.
  1103. */
  1104. static int mv_port_start(struct ata_port *ap)
  1105. {
  1106. struct device *dev = ap->host->dev;
  1107. struct mv_host_priv *hpriv = ap->host->private_data;
  1108. struct mv_port_priv *pp;
  1109. int tag;
  1110. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  1111. if (!pp)
  1112. return -ENOMEM;
  1113. ap->private_data = pp;
  1114. pp->crqb = dma_pool_alloc(hpriv->crqb_pool, GFP_KERNEL, &pp->crqb_dma);
  1115. if (!pp->crqb)
  1116. return -ENOMEM;
  1117. memset(pp->crqb, 0, MV_CRQB_Q_SZ);
  1118. pp->crpb = dma_pool_alloc(hpriv->crpb_pool, GFP_KERNEL, &pp->crpb_dma);
  1119. if (!pp->crpb)
  1120. goto out_port_free_dma_mem;
  1121. memset(pp->crpb, 0, MV_CRPB_Q_SZ);
  1122. /*
  1123. * For GEN_I, there's no NCQ, so we only allocate a single sg_tbl.
  1124. * For later hardware, we need one unique sg_tbl per NCQ tag.
  1125. */
  1126. for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) {
  1127. if (tag == 0 || !IS_GEN_I(hpriv)) {
  1128. pp->sg_tbl[tag] = dma_pool_alloc(hpriv->sg_tbl_pool,
  1129. GFP_KERNEL, &pp->sg_tbl_dma[tag]);
  1130. if (!pp->sg_tbl[tag])
  1131. goto out_port_free_dma_mem;
  1132. } else {
  1133. pp->sg_tbl[tag] = pp->sg_tbl[0];
  1134. pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0];
  1135. }
  1136. }
  1137. return 0;
  1138. out_port_free_dma_mem:
  1139. mv_port_free_dma_mem(ap);
  1140. return -ENOMEM;
  1141. }
  1142. /**
  1143. * mv_port_stop - Port specific cleanup/stop routine.
  1144. * @ap: ATA channel to manipulate
  1145. *
  1146. * Stop DMA, cleanup port memory.
  1147. *
  1148. * LOCKING:
  1149. * This routine uses the host lock to protect the DMA stop.
  1150. */
  1151. static void mv_port_stop(struct ata_port *ap)
  1152. {
  1153. mv_stop_edma(ap);
  1154. mv_port_free_dma_mem(ap);
  1155. }
  1156. /**
  1157. * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
  1158. * @qc: queued command whose SG list to source from
  1159. *
  1160. * Populate the SG list and mark the last entry.
  1161. *
  1162. * LOCKING:
  1163. * Inherited from caller.
  1164. */
  1165. static void mv_fill_sg(struct ata_queued_cmd *qc)
  1166. {
  1167. struct mv_port_priv *pp = qc->ap->private_data;
  1168. struct scatterlist *sg;
  1169. struct mv_sg *mv_sg, *last_sg = NULL;
  1170. unsigned int si;
  1171. mv_sg = pp->sg_tbl[qc->tag];
  1172. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  1173. dma_addr_t addr = sg_dma_address(sg);
  1174. u32 sg_len = sg_dma_len(sg);
  1175. while (sg_len) {
  1176. u32 offset = addr & 0xffff;
  1177. u32 len = sg_len;
  1178. if ((offset + sg_len > 0x10000))
  1179. len = 0x10000 - offset;
  1180. mv_sg->addr = cpu_to_le32(addr & 0xffffffff);
  1181. mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
  1182. mv_sg->flags_size = cpu_to_le32(len & 0xffff);
  1183. sg_len -= len;
  1184. addr += len;
  1185. last_sg = mv_sg;
  1186. mv_sg++;
  1187. }
  1188. }
  1189. if (likely(last_sg))
  1190. last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
  1191. }
  1192. static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
  1193. {
  1194. u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
  1195. (last ? CRQB_CMD_LAST : 0);
  1196. *cmdw = cpu_to_le16(tmp);
  1197. }
  1198. /**
  1199. * mv_qc_prep - Host specific command preparation.
  1200. * @qc: queued command to prepare
  1201. *
  1202. * This routine simply redirects to the general purpose routine
  1203. * if command is not DMA. Else, it handles prep of the CRQB
  1204. * (command request block), does some sanity checking, and calls
  1205. * the SG load routine.
  1206. *
  1207. * LOCKING:
  1208. * Inherited from caller.
  1209. */
  1210. static void mv_qc_prep(struct ata_queued_cmd *qc)
  1211. {
  1212. struct ata_port *ap = qc->ap;
  1213. struct mv_port_priv *pp = ap->private_data;
  1214. __le16 *cw;
  1215. struct ata_taskfile *tf;
  1216. u16 flags = 0;
  1217. unsigned in_index;
  1218. if ((qc->tf.protocol != ATA_PROT_DMA) &&
  1219. (qc->tf.protocol != ATA_PROT_NCQ))
  1220. return;
  1221. /* Fill in command request block
  1222. */
  1223. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  1224. flags |= CRQB_FLAG_READ;
  1225. WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
  1226. flags |= qc->tag << CRQB_TAG_SHIFT;
  1227. flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT;
  1228. /* get current queue index from software */
  1229. in_index = pp->req_idx;
  1230. pp->crqb[in_index].sg_addr =
  1231. cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff);
  1232. pp->crqb[in_index].sg_addr_hi =
  1233. cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16);
  1234. pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags);
  1235. cw = &pp->crqb[in_index].ata_cmd[0];
  1236. tf = &qc->tf;
  1237. /* Sadly, the CRQB cannot accomodate all registers--there are
  1238. * only 11 bytes...so we must pick and choose required
  1239. * registers based on the command. So, we drop feature and
  1240. * hob_feature for [RW] DMA commands, but they are needed for
  1241. * NCQ. NCQ will drop hob_nsect.
  1242. */
  1243. switch (tf->command) {
  1244. case ATA_CMD_READ:
  1245. case ATA_CMD_READ_EXT:
  1246. case ATA_CMD_WRITE:
  1247. case ATA_CMD_WRITE_EXT:
  1248. case ATA_CMD_WRITE_FUA_EXT:
  1249. mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
  1250. break;
  1251. case ATA_CMD_FPDMA_READ:
  1252. case ATA_CMD_FPDMA_WRITE:
  1253. mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
  1254. mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
  1255. break;
  1256. default:
  1257. /* The only other commands EDMA supports in non-queued and
  1258. * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
  1259. * of which are defined/used by Linux. If we get here, this
  1260. * driver needs work.
  1261. *
  1262. * FIXME: modify libata to give qc_prep a return value and
  1263. * return error here.
  1264. */
  1265. BUG_ON(tf->command);
  1266. break;
  1267. }
  1268. mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
  1269. mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
  1270. mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
  1271. mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
  1272. mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
  1273. mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
  1274. mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
  1275. mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
  1276. mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
  1277. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  1278. return;
  1279. mv_fill_sg(qc);
  1280. }
  1281. /**
  1282. * mv_qc_prep_iie - Host specific command preparation.
  1283. * @qc: queued command to prepare
  1284. *
  1285. * This routine simply redirects to the general purpose routine
  1286. * if command is not DMA. Else, it handles prep of the CRQB
  1287. * (command request block), does some sanity checking, and calls
  1288. * the SG load routine.
  1289. *
  1290. * LOCKING:
  1291. * Inherited from caller.
  1292. */
  1293. static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
  1294. {
  1295. struct ata_port *ap = qc->ap;
  1296. struct mv_port_priv *pp = ap->private_data;
  1297. struct mv_crqb_iie *crqb;
  1298. struct ata_taskfile *tf;
  1299. unsigned in_index;
  1300. u32 flags = 0;
  1301. if ((qc->tf.protocol != ATA_PROT_DMA) &&
  1302. (qc->tf.protocol != ATA_PROT_NCQ))
  1303. return;
  1304. /* Fill in Gen IIE command request block */
  1305. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  1306. flags |= CRQB_FLAG_READ;
  1307. WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
  1308. flags |= qc->tag << CRQB_TAG_SHIFT;
  1309. flags |= qc->tag << CRQB_HOSTQ_SHIFT;
  1310. flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT;
  1311. /* get current queue index from software */
  1312. in_index = pp->req_idx;
  1313. crqb = (struct mv_crqb_iie *) &pp->crqb[in_index];
  1314. crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff);
  1315. crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16);
  1316. crqb->flags = cpu_to_le32(flags);
  1317. tf = &qc->tf;
  1318. crqb->ata_cmd[0] = cpu_to_le32(
  1319. (tf->command << 16) |
  1320. (tf->feature << 24)
  1321. );
  1322. crqb->ata_cmd[1] = cpu_to_le32(
  1323. (tf->lbal << 0) |
  1324. (tf->lbam << 8) |
  1325. (tf->lbah << 16) |
  1326. (tf->device << 24)
  1327. );
  1328. crqb->ata_cmd[2] = cpu_to_le32(
  1329. (tf->hob_lbal << 0) |
  1330. (tf->hob_lbam << 8) |
  1331. (tf->hob_lbah << 16) |
  1332. (tf->hob_feature << 24)
  1333. );
  1334. crqb->ata_cmd[3] = cpu_to_le32(
  1335. (tf->nsect << 0) |
  1336. (tf->hob_nsect << 8)
  1337. );
  1338. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  1339. return;
  1340. mv_fill_sg(qc);
  1341. }
  1342. /**
  1343. * mv_qc_issue - Initiate a command to the host
  1344. * @qc: queued command to start
  1345. *
  1346. * This routine simply redirects to the general purpose routine
  1347. * if command is not DMA. Else, it sanity checks our local
  1348. * caches of the request producer/consumer indices then enables
  1349. * DMA and bumps the request producer index.
  1350. *
  1351. * LOCKING:
  1352. * Inherited from caller.
  1353. */
  1354. static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
  1355. {
  1356. struct ata_port *ap = qc->ap;
  1357. void __iomem *port_mmio = mv_ap_base(ap);
  1358. struct mv_port_priv *pp = ap->private_data;
  1359. u32 in_index;
  1360. if ((qc->tf.protocol != ATA_PROT_DMA) &&
  1361. (qc->tf.protocol != ATA_PROT_NCQ)) {
  1362. /*
  1363. * We're about to send a non-EDMA capable command to the
  1364. * port. Turn off EDMA so there won't be problems accessing
  1365. * shadow block, etc registers.
  1366. */
  1367. mv_stop_edma(ap);
  1368. mv_pmp_select(ap, qc->dev->link->pmp);
  1369. return ata_sff_qc_issue(qc);
  1370. }
  1371. mv_start_dma(ap, port_mmio, pp, qc->tf.protocol);
  1372. pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK;
  1373. in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
  1374. /* and write the request in pointer to kick the EDMA to life */
  1375. writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index,
  1376. port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
  1377. return 0;
  1378. }
  1379. static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
  1380. {
  1381. struct mv_port_priv *pp = ap->private_data;
  1382. struct ata_queued_cmd *qc;
  1383. if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
  1384. return NULL;
  1385. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1386. if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
  1387. qc = NULL;
  1388. return qc;
  1389. }
  1390. static void mv_unexpected_intr(struct ata_port *ap)
  1391. {
  1392. struct mv_port_priv *pp = ap->private_data;
  1393. struct ata_eh_info *ehi = &ap->link.eh_info;
  1394. char *when = "";
  1395. /*
  1396. * We got a device interrupt from something that
  1397. * was supposed to be using EDMA or polling.
  1398. */
  1399. ata_ehi_clear_desc(ehi);
  1400. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
  1401. when = " while EDMA enabled";
  1402. } else {
  1403. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1404. if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
  1405. when = " while polling";
  1406. }
  1407. ata_ehi_push_desc(ehi, "unexpected device interrupt%s", when);
  1408. ehi->err_mask |= AC_ERR_OTHER;
  1409. ehi->action |= ATA_EH_RESET;
  1410. ata_port_freeze(ap);
  1411. }
  1412. /**
  1413. * mv_err_intr - Handle error interrupts on the port
  1414. * @ap: ATA channel to manipulate
  1415. * @qc: affected command (non-NCQ), or NULL
  1416. *
  1417. * Most cases require a full reset of the chip's state machine,
  1418. * which also performs a COMRESET.
  1419. * Also, if the port disabled DMA, update our cached copy to match.
  1420. *
  1421. * LOCKING:
  1422. * Inherited from caller.
  1423. */
  1424. static void mv_err_intr(struct ata_port *ap)
  1425. {
  1426. void __iomem *port_mmio = mv_ap_base(ap);
  1427. u32 edma_err_cause, eh_freeze_mask, serr = 0;
  1428. struct mv_port_priv *pp = ap->private_data;
  1429. struct mv_host_priv *hpriv = ap->host->private_data;
  1430. unsigned int action = 0, err_mask = 0;
  1431. struct ata_eh_info *ehi = &ap->link.eh_info;
  1432. struct ata_queued_cmd *qc;
  1433. int abort = 0;
  1434. /*
  1435. * Read and clear the SError and err_cause bits.
  1436. */
  1437. sata_scr_read(&ap->link, SCR_ERROR, &serr);
  1438. sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
  1439. edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1440. writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1441. ata_port_printk(ap, KERN_INFO, "%s: err_cause=%08x pp_flags=0x%x\n",
  1442. __func__, edma_err_cause, pp->pp_flags);
  1443. qc = mv_get_active_qc(ap);
  1444. ata_ehi_clear_desc(ehi);
  1445. ata_ehi_push_desc(ehi, "edma_err_cause=%08x pp_flags=%08x",
  1446. edma_err_cause, pp->pp_flags);
  1447. /*
  1448. * All generations share these EDMA error cause bits:
  1449. */
  1450. if (edma_err_cause & EDMA_ERR_DEV) {
  1451. err_mask |= AC_ERR_DEV;
  1452. action |= ATA_EH_RESET;
  1453. ata_ehi_push_desc(ehi, "dev error");
  1454. }
  1455. if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
  1456. EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR |
  1457. EDMA_ERR_INTRL_PAR)) {
  1458. err_mask |= AC_ERR_ATA_BUS;
  1459. action |= ATA_EH_RESET;
  1460. ata_ehi_push_desc(ehi, "parity error");
  1461. }
  1462. if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) {
  1463. ata_ehi_hotplugged(ehi);
  1464. ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ?
  1465. "dev disconnect" : "dev connect");
  1466. action |= ATA_EH_RESET;
  1467. }
  1468. /*
  1469. * Gen-I has a different SELF_DIS bit,
  1470. * different FREEZE bits, and no SERR bit:
  1471. */
  1472. if (IS_GEN_I(hpriv)) {
  1473. eh_freeze_mask = EDMA_EH_FREEZE_5;
  1474. if (edma_err_cause & EDMA_ERR_SELF_DIS_5) {
  1475. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  1476. ata_ehi_push_desc(ehi, "EDMA self-disable");
  1477. }
  1478. } else {
  1479. eh_freeze_mask = EDMA_EH_FREEZE;
  1480. if (edma_err_cause & EDMA_ERR_SELF_DIS) {
  1481. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  1482. ata_ehi_push_desc(ehi, "EDMA self-disable");
  1483. }
  1484. if (edma_err_cause & EDMA_ERR_SERR) {
  1485. ata_ehi_push_desc(ehi, "SError=%08x", serr);
  1486. err_mask |= AC_ERR_ATA_BUS;
  1487. action |= ATA_EH_RESET;
  1488. }
  1489. }
  1490. if (!err_mask) {
  1491. err_mask = AC_ERR_OTHER;
  1492. action |= ATA_EH_RESET;
  1493. }
  1494. ehi->serror |= serr;
  1495. ehi->action |= action;
  1496. if (qc)
  1497. qc->err_mask |= err_mask;
  1498. else
  1499. ehi->err_mask |= err_mask;
  1500. if (err_mask == AC_ERR_DEV) {
  1501. /*
  1502. * Cannot do ata_port_freeze() here,
  1503. * because it would kill PIO access,
  1504. * which is needed for further diagnosis.
  1505. */
  1506. mv_eh_freeze(ap);
  1507. abort = 1;
  1508. } else if (edma_err_cause & eh_freeze_mask) {
  1509. /*
  1510. * Note to self: ata_port_freeze() calls ata_port_abort()
  1511. */
  1512. ata_port_freeze(ap);
  1513. } else {
  1514. abort = 1;
  1515. }
  1516. if (abort) {
  1517. if (qc)
  1518. ata_link_abort(qc->dev->link);
  1519. else
  1520. ata_port_abort(ap);
  1521. }
  1522. }
  1523. static void mv_process_crpb_response(struct ata_port *ap,
  1524. struct mv_crpb *response, unsigned int tag, int ncq_enabled)
  1525. {
  1526. struct ata_queued_cmd *qc = ata_qc_from_tag(ap, tag);
  1527. if (qc) {
  1528. u8 ata_status;
  1529. u16 edma_status = le16_to_cpu(response->flags);
  1530. /*
  1531. * edma_status from a response queue entry:
  1532. * LSB is from EDMA_ERR_IRQ_CAUSE_OFS (non-NCQ only).
  1533. * MSB is saved ATA status from command completion.
  1534. */
  1535. if (!ncq_enabled) {
  1536. u8 err_cause = edma_status & 0xff & ~EDMA_ERR_DEV;
  1537. if (err_cause) {
  1538. /*
  1539. * Error will be seen/handled by mv_err_intr().
  1540. * So do nothing at all here.
  1541. */
  1542. return;
  1543. }
  1544. }
  1545. ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT;
  1546. if (!ac_err_mask(ata_status))
  1547. ata_qc_complete(qc);
  1548. /* else: leave it for mv_err_intr() */
  1549. } else {
  1550. ata_port_printk(ap, KERN_ERR, "%s: no qc for tag=%d\n",
  1551. __func__, tag);
  1552. }
  1553. }
  1554. static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp)
  1555. {
  1556. void __iomem *port_mmio = mv_ap_base(ap);
  1557. struct mv_host_priv *hpriv = ap->host->private_data;
  1558. u32 in_index;
  1559. bool work_done = false;
  1560. int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN);
  1561. /* Get the hardware queue position index */
  1562. in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
  1563. >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
  1564. /* Process new responses from since the last time we looked */
  1565. while (in_index != pp->resp_idx) {
  1566. unsigned int tag;
  1567. struct mv_crpb *response = &pp->crpb[pp->resp_idx];
  1568. pp->resp_idx = (pp->resp_idx + 1) & MV_MAX_Q_DEPTH_MASK;
  1569. if (IS_GEN_I(hpriv)) {
  1570. /* 50xx: no NCQ, only one command active at a time */
  1571. tag = ap->link.active_tag;
  1572. } else {
  1573. /* Gen II/IIE: get command tag from CRPB entry */
  1574. tag = le16_to_cpu(response->id) & 0x1f;
  1575. }
  1576. mv_process_crpb_response(ap, response, tag, ncq_enabled);
  1577. work_done = true;
  1578. }
  1579. /* Update the software queue position index in hardware */
  1580. if (work_done)
  1581. writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
  1582. (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT),
  1583. port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  1584. }
  1585. /**
  1586. * mv_host_intr - Handle all interrupts on the given host controller
  1587. * @host: host specific structure
  1588. * @main_irq_cause: Main interrupt cause register for the chip.
  1589. *
  1590. * LOCKING:
  1591. * Inherited from caller.
  1592. */
  1593. static int mv_host_intr(struct ata_host *host, u32 main_irq_cause)
  1594. {
  1595. struct mv_host_priv *hpriv = host->private_data;
  1596. void __iomem *mmio = hpriv->base, *hc_mmio = NULL;
  1597. u32 hc_irq_cause = 0;
  1598. unsigned int handled = 0, port;
  1599. for (port = 0; port < hpriv->n_ports; port++) {
  1600. struct ata_port *ap = host->ports[port];
  1601. struct mv_port_priv *pp;
  1602. unsigned int shift, hardport, port_cause;
  1603. /*
  1604. * When we move to the second hc, flag our cached
  1605. * copies of hc_mmio (and hc_irq_cause) as invalid again.
  1606. */
  1607. if (port == MV_PORTS_PER_HC)
  1608. hc_mmio = NULL;
  1609. /*
  1610. * Do nothing if port is not interrupting or is disabled:
  1611. */
  1612. MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
  1613. port_cause = (main_irq_cause >> shift) & (DONE_IRQ | ERR_IRQ);
  1614. if (!port_cause || !ap || (ap->flags & ATA_FLAG_DISABLED))
  1615. continue;
  1616. /*
  1617. * Each hc within the host has its own hc_irq_cause register.
  1618. * We defer reading it until we know we need it, right now:
  1619. *
  1620. * FIXME later: we don't really need to read this register
  1621. * (some logic changes required below if we go that way),
  1622. * because it doesn't tell us anything new. But we do need
  1623. * to write to it, outside the top of this loop,
  1624. * to reset the interrupt triggers for next time.
  1625. */
  1626. if (!hc_mmio) {
  1627. hc_mmio = mv_hc_base_from_port(mmio, port);
  1628. hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
  1629. writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
  1630. handled = 1;
  1631. }
  1632. /*
  1633. * Process completed CRPB response(s) before other events.
  1634. */
  1635. pp = ap->private_data;
  1636. if (hc_irq_cause & (DMA_IRQ << hardport)) {
  1637. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN)
  1638. mv_process_crpb_entries(ap, pp);
  1639. }
  1640. /*
  1641. * Handle chip-reported errors, or continue on to handle PIO.
  1642. */
  1643. if (unlikely(port_cause & ERR_IRQ)) {
  1644. mv_err_intr(ap);
  1645. } else if (hc_irq_cause & (DEV_IRQ << hardport)) {
  1646. if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
  1647. struct ata_queued_cmd *qc = mv_get_active_qc(ap);
  1648. if (qc) {
  1649. ata_sff_host_intr(ap, qc);
  1650. continue;
  1651. }
  1652. }
  1653. mv_unexpected_intr(ap);
  1654. }
  1655. }
  1656. return handled;
  1657. }
  1658. static int mv_pci_error(struct ata_host *host, void __iomem *mmio)
  1659. {
  1660. struct mv_host_priv *hpriv = host->private_data;
  1661. struct ata_port *ap;
  1662. struct ata_queued_cmd *qc;
  1663. struct ata_eh_info *ehi;
  1664. unsigned int i, err_mask, printed = 0;
  1665. u32 err_cause;
  1666. err_cause = readl(mmio + hpriv->irq_cause_ofs);
  1667. dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n",
  1668. err_cause);
  1669. DPRINTK("All regs @ PCI error\n");
  1670. mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
  1671. writelfl(0, mmio + hpriv->irq_cause_ofs);
  1672. for (i = 0; i < host->n_ports; i++) {
  1673. ap = host->ports[i];
  1674. if (!ata_link_offline(&ap->link)) {
  1675. ehi = &ap->link.eh_info;
  1676. ata_ehi_clear_desc(ehi);
  1677. if (!printed++)
  1678. ata_ehi_push_desc(ehi,
  1679. "PCI err cause 0x%08x", err_cause);
  1680. err_mask = AC_ERR_HOST_BUS;
  1681. ehi->action = ATA_EH_RESET;
  1682. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1683. if (qc)
  1684. qc->err_mask |= err_mask;
  1685. else
  1686. ehi->err_mask |= err_mask;
  1687. ata_port_freeze(ap);
  1688. }
  1689. }
  1690. return 1; /* handled */
  1691. }
  1692. /**
  1693. * mv_interrupt - Main interrupt event handler
  1694. * @irq: unused
  1695. * @dev_instance: private data; in this case the host structure
  1696. *
  1697. * Read the read only register to determine if any host
  1698. * controllers have pending interrupts. If so, call lower level
  1699. * routine to handle. Also check for PCI errors which are only
  1700. * reported here.
  1701. *
  1702. * LOCKING:
  1703. * This routine holds the host lock while processing pending
  1704. * interrupts.
  1705. */
  1706. static irqreturn_t mv_interrupt(int irq, void *dev_instance)
  1707. {
  1708. struct ata_host *host = dev_instance;
  1709. struct mv_host_priv *hpriv = host->private_data;
  1710. unsigned int handled = 0;
  1711. u32 main_irq_cause, main_irq_mask;
  1712. spin_lock(&host->lock);
  1713. main_irq_cause = readl(hpriv->main_irq_cause_addr);
  1714. main_irq_mask = readl(hpriv->main_irq_mask_addr);
  1715. /*
  1716. * Deal with cases where we either have nothing pending, or have read
  1717. * a bogus register value which can indicate HW removal or PCI fault.
  1718. */
  1719. if ((main_irq_cause & main_irq_mask) && (main_irq_cause != 0xffffffffU)) {
  1720. if (unlikely((main_irq_cause & PCI_ERR) && HAS_PCI(host)))
  1721. handled = mv_pci_error(host, hpriv->base);
  1722. else
  1723. handled = mv_host_intr(host, main_irq_cause);
  1724. }
  1725. spin_unlock(&host->lock);
  1726. return IRQ_RETVAL(handled);
  1727. }
  1728. static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
  1729. {
  1730. unsigned int ofs;
  1731. switch (sc_reg_in) {
  1732. case SCR_STATUS:
  1733. case SCR_ERROR:
  1734. case SCR_CONTROL:
  1735. ofs = sc_reg_in * sizeof(u32);
  1736. break;
  1737. default:
  1738. ofs = 0xffffffffU;
  1739. break;
  1740. }
  1741. return ofs;
  1742. }
  1743. static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
  1744. {
  1745. struct mv_host_priv *hpriv = ap->host->private_data;
  1746. void __iomem *mmio = hpriv->base;
  1747. void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
  1748. unsigned int ofs = mv5_scr_offset(sc_reg_in);
  1749. if (ofs != 0xffffffffU) {
  1750. *val = readl(addr + ofs);
  1751. return 0;
  1752. } else
  1753. return -EINVAL;
  1754. }
  1755. static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
  1756. {
  1757. struct mv_host_priv *hpriv = ap->host->private_data;
  1758. void __iomem *mmio = hpriv->base;
  1759. void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
  1760. unsigned int ofs = mv5_scr_offset(sc_reg_in);
  1761. if (ofs != 0xffffffffU) {
  1762. writelfl(val, addr + ofs);
  1763. return 0;
  1764. } else
  1765. return -EINVAL;
  1766. }
  1767. static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio)
  1768. {
  1769. struct pci_dev *pdev = to_pci_dev(host->dev);
  1770. int early_5080;
  1771. early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0);
  1772. if (!early_5080) {
  1773. u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1774. tmp |= (1 << 0);
  1775. writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1776. }
  1777. mv_reset_pci_bus(host, mmio);
  1778. }
  1779. static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
  1780. {
  1781. writel(0x0fcfffff, mmio + MV_FLASH_CTL_OFS);
  1782. }
  1783. static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
  1784. void __iomem *mmio)
  1785. {
  1786. void __iomem *phy_mmio = mv5_phy_base(mmio, idx);
  1787. u32 tmp;
  1788. tmp = readl(phy_mmio + MV5_PHY_MODE);
  1789. hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */
  1790. hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */
  1791. }
  1792. static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
  1793. {
  1794. u32 tmp;
  1795. writel(0, mmio + MV_GPIO_PORT_CTL_OFS);
  1796. /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */
  1797. tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1798. tmp |= ~(1 << 0);
  1799. writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1800. }
  1801. static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  1802. unsigned int port)
  1803. {
  1804. void __iomem *phy_mmio = mv5_phy_base(mmio, port);
  1805. const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5);
  1806. u32 tmp;
  1807. int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0);
  1808. if (fix_apm_sq) {
  1809. tmp = readl(phy_mmio + MV5_LTMODE_OFS);
  1810. tmp |= (1 << 19);
  1811. writel(tmp, phy_mmio + MV5_LTMODE_OFS);
  1812. tmp = readl(phy_mmio + MV5_PHY_CTL_OFS);
  1813. tmp &= ~0x3;
  1814. tmp |= 0x1;
  1815. writel(tmp, phy_mmio + MV5_PHY_CTL_OFS);
  1816. }
  1817. tmp = readl(phy_mmio + MV5_PHY_MODE);
  1818. tmp &= ~mask;
  1819. tmp |= hpriv->signal[port].pre;
  1820. tmp |= hpriv->signal[port].amps;
  1821. writel(tmp, phy_mmio + MV5_PHY_MODE);
  1822. }
  1823. #undef ZERO
  1824. #define ZERO(reg) writel(0, port_mmio + (reg))
  1825. static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio,
  1826. unsigned int port)
  1827. {
  1828. void __iomem *port_mmio = mv_port_base(mmio, port);
  1829. mv_reset_channel(hpriv, mmio, port);
  1830. ZERO(0x028); /* command */
  1831. writel(0x11f, port_mmio + EDMA_CFG_OFS);
  1832. ZERO(0x004); /* timer */
  1833. ZERO(0x008); /* irq err cause */
  1834. ZERO(0x00c); /* irq err mask */
  1835. ZERO(0x010); /* rq bah */
  1836. ZERO(0x014); /* rq inp */
  1837. ZERO(0x018); /* rq outp */
  1838. ZERO(0x01c); /* respq bah */
  1839. ZERO(0x024); /* respq outp */
  1840. ZERO(0x020); /* respq inp */
  1841. ZERO(0x02c); /* test control */
  1842. writel(0xbc, port_mmio + EDMA_IORDY_TMOUT_OFS);
  1843. }
  1844. #undef ZERO
  1845. #define ZERO(reg) writel(0, hc_mmio + (reg))
  1846. static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1847. unsigned int hc)
  1848. {
  1849. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  1850. u32 tmp;
  1851. ZERO(0x00c);
  1852. ZERO(0x010);
  1853. ZERO(0x014);
  1854. ZERO(0x018);
  1855. tmp = readl(hc_mmio + 0x20);
  1856. tmp &= 0x1c1c1c1c;
  1857. tmp |= 0x03030303;
  1858. writel(tmp, hc_mmio + 0x20);
  1859. }
  1860. #undef ZERO
  1861. static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1862. unsigned int n_hc)
  1863. {
  1864. unsigned int hc, port;
  1865. for (hc = 0; hc < n_hc; hc++) {
  1866. for (port = 0; port < MV_PORTS_PER_HC; port++)
  1867. mv5_reset_hc_port(hpriv, mmio,
  1868. (hc * MV_PORTS_PER_HC) + port);
  1869. mv5_reset_one_hc(hpriv, mmio, hc);
  1870. }
  1871. return 0;
  1872. }
  1873. #undef ZERO
  1874. #define ZERO(reg) writel(0, mmio + (reg))
  1875. static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio)
  1876. {
  1877. struct mv_host_priv *hpriv = host->private_data;
  1878. u32 tmp;
  1879. tmp = readl(mmio + MV_PCI_MODE_OFS);
  1880. tmp &= 0xff00ffff;
  1881. writel(tmp, mmio + MV_PCI_MODE_OFS);
  1882. ZERO(MV_PCI_DISC_TIMER);
  1883. ZERO(MV_PCI_MSI_TRIGGER);
  1884. writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT_OFS);
  1885. ZERO(PCI_HC_MAIN_IRQ_MASK_OFS);
  1886. ZERO(MV_PCI_SERR_MASK);
  1887. ZERO(hpriv->irq_cause_ofs);
  1888. ZERO(hpriv->irq_mask_ofs);
  1889. ZERO(MV_PCI_ERR_LOW_ADDRESS);
  1890. ZERO(MV_PCI_ERR_HIGH_ADDRESS);
  1891. ZERO(MV_PCI_ERR_ATTRIBUTE);
  1892. ZERO(MV_PCI_ERR_COMMAND);
  1893. }
  1894. #undef ZERO
  1895. static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
  1896. {
  1897. u32 tmp;
  1898. mv5_reset_flash(hpriv, mmio);
  1899. tmp = readl(mmio + MV_GPIO_PORT_CTL_OFS);
  1900. tmp &= 0x3;
  1901. tmp |= (1 << 5) | (1 << 6);
  1902. writel(tmp, mmio + MV_GPIO_PORT_CTL_OFS);
  1903. }
  1904. /**
  1905. * mv6_reset_hc - Perform the 6xxx global soft reset
  1906. * @mmio: base address of the HBA
  1907. *
  1908. * This routine only applies to 6xxx parts.
  1909. *
  1910. * LOCKING:
  1911. * Inherited from caller.
  1912. */
  1913. static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1914. unsigned int n_hc)
  1915. {
  1916. void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS;
  1917. int i, rc = 0;
  1918. u32 t;
  1919. /* Following procedure defined in PCI "main command and status
  1920. * register" table.
  1921. */
  1922. t = readl(reg);
  1923. writel(t | STOP_PCI_MASTER, reg);
  1924. for (i = 0; i < 1000; i++) {
  1925. udelay(1);
  1926. t = readl(reg);
  1927. if (PCI_MASTER_EMPTY & t)
  1928. break;
  1929. }
  1930. if (!(PCI_MASTER_EMPTY & t)) {
  1931. printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
  1932. rc = 1;
  1933. goto done;
  1934. }
  1935. /* set reset */
  1936. i = 5;
  1937. do {
  1938. writel(t | GLOB_SFT_RST, reg);
  1939. t = readl(reg);
  1940. udelay(1);
  1941. } while (!(GLOB_SFT_RST & t) && (i-- > 0));
  1942. if (!(GLOB_SFT_RST & t)) {
  1943. printk(KERN_ERR DRV_NAME ": can't set global reset\n");
  1944. rc = 1;
  1945. goto done;
  1946. }
  1947. /* clear reset and *reenable the PCI master* (not mentioned in spec) */
  1948. i = 5;
  1949. do {
  1950. writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
  1951. t = readl(reg);
  1952. udelay(1);
  1953. } while ((GLOB_SFT_RST & t) && (i-- > 0));
  1954. if (GLOB_SFT_RST & t) {
  1955. printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
  1956. rc = 1;
  1957. }
  1958. done:
  1959. return rc;
  1960. }
  1961. static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
  1962. void __iomem *mmio)
  1963. {
  1964. void __iomem *port_mmio;
  1965. u32 tmp;
  1966. tmp = readl(mmio + MV_RESET_CFG_OFS);
  1967. if ((tmp & (1 << 0)) == 0) {
  1968. hpriv->signal[idx].amps = 0x7 << 8;
  1969. hpriv->signal[idx].pre = 0x1 << 5;
  1970. return;
  1971. }
  1972. port_mmio = mv_port_base(mmio, idx);
  1973. tmp = readl(port_mmio + PHY_MODE2);
  1974. hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
  1975. hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
  1976. }
  1977. static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
  1978. {
  1979. writel(0x00000060, mmio + MV_GPIO_PORT_CTL_OFS);
  1980. }
  1981. static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  1982. unsigned int port)
  1983. {
  1984. void __iomem *port_mmio = mv_port_base(mmio, port);
  1985. u32 hp_flags = hpriv->hp_flags;
  1986. int fix_phy_mode2 =
  1987. hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
  1988. int fix_phy_mode4 =
  1989. hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
  1990. u32 m2, tmp;
  1991. if (fix_phy_mode2) {
  1992. m2 = readl(port_mmio + PHY_MODE2);
  1993. m2 &= ~(1 << 16);
  1994. m2 |= (1 << 31);
  1995. writel(m2, port_mmio + PHY_MODE2);
  1996. udelay(200);
  1997. m2 = readl(port_mmio + PHY_MODE2);
  1998. m2 &= ~((1 << 16) | (1 << 31));
  1999. writel(m2, port_mmio + PHY_MODE2);
  2000. udelay(200);
  2001. }
  2002. /* who knows what this magic does */
  2003. tmp = readl(port_mmio + PHY_MODE3);
  2004. tmp &= ~0x7F800000;
  2005. tmp |= 0x2A800000;
  2006. writel(tmp, port_mmio + PHY_MODE3);
  2007. if (fix_phy_mode4) {
  2008. u32 m4;
  2009. m4 = readl(port_mmio + PHY_MODE4);
  2010. if (hp_flags & MV_HP_ERRATA_60X1B2)
  2011. tmp = readl(port_mmio + PHY_MODE3);
  2012. /* workaround for errata FEr SATA#10 (part 1) */
  2013. m4 = (m4 & ~(1 << 1)) | (1 << 0);
  2014. writel(m4, port_mmio + PHY_MODE4);
  2015. if (hp_flags & MV_HP_ERRATA_60X1B2)
  2016. writel(tmp, port_mmio + PHY_MODE3);
  2017. }
  2018. /* Revert values of pre-emphasis and signal amps to the saved ones */
  2019. m2 = readl(port_mmio + PHY_MODE2);
  2020. m2 &= ~MV_M2_PREAMP_MASK;
  2021. m2 |= hpriv->signal[port].amps;
  2022. m2 |= hpriv->signal[port].pre;
  2023. m2 &= ~(1 << 16);
  2024. /* according to mvSata 3.6.1, some IIE values are fixed */
  2025. if (IS_GEN_IIE(hpriv)) {
  2026. m2 &= ~0xC30FF01F;
  2027. m2 |= 0x0000900F;
  2028. }
  2029. writel(m2, port_mmio + PHY_MODE2);
  2030. }
  2031. /* TODO: use the generic LED interface to configure the SATA Presence */
  2032. /* & Acitivy LEDs on the board */
  2033. static void mv_soc_enable_leds(struct mv_host_priv *hpriv,
  2034. void __iomem *mmio)
  2035. {
  2036. return;
  2037. }
  2038. static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx,
  2039. void __iomem *mmio)
  2040. {
  2041. void __iomem *port_mmio;
  2042. u32 tmp;
  2043. port_mmio = mv_port_base(mmio, idx);
  2044. tmp = readl(port_mmio + PHY_MODE2);
  2045. hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
  2046. hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
  2047. }
  2048. #undef ZERO
  2049. #define ZERO(reg) writel(0, port_mmio + (reg))
  2050. static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv,
  2051. void __iomem *mmio, unsigned int port)
  2052. {
  2053. void __iomem *port_mmio = mv_port_base(mmio, port);
  2054. mv_reset_channel(hpriv, mmio, port);
  2055. ZERO(0x028); /* command */
  2056. writel(0x101f, port_mmio + EDMA_CFG_OFS);
  2057. ZERO(0x004); /* timer */
  2058. ZERO(0x008); /* irq err cause */
  2059. ZERO(0x00c); /* irq err mask */
  2060. ZERO(0x010); /* rq bah */
  2061. ZERO(0x014); /* rq inp */
  2062. ZERO(0x018); /* rq outp */
  2063. ZERO(0x01c); /* respq bah */
  2064. ZERO(0x024); /* respq outp */
  2065. ZERO(0x020); /* respq inp */
  2066. ZERO(0x02c); /* test control */
  2067. writel(0xbc, port_mmio + EDMA_IORDY_TMOUT_OFS);
  2068. }
  2069. #undef ZERO
  2070. #define ZERO(reg) writel(0, hc_mmio + (reg))
  2071. static void mv_soc_reset_one_hc(struct mv_host_priv *hpriv,
  2072. void __iomem *mmio)
  2073. {
  2074. void __iomem *hc_mmio = mv_hc_base(mmio, 0);
  2075. ZERO(0x00c);
  2076. ZERO(0x010);
  2077. ZERO(0x014);
  2078. }
  2079. #undef ZERO
  2080. static int mv_soc_reset_hc(struct mv_host_priv *hpriv,
  2081. void __iomem *mmio, unsigned int n_hc)
  2082. {
  2083. unsigned int port;
  2084. for (port = 0; port < hpriv->n_ports; port++)
  2085. mv_soc_reset_hc_port(hpriv, mmio, port);
  2086. mv_soc_reset_one_hc(hpriv, mmio);
  2087. return 0;
  2088. }
  2089. static void mv_soc_reset_flash(struct mv_host_priv *hpriv,
  2090. void __iomem *mmio)
  2091. {
  2092. return;
  2093. }
  2094. static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio)
  2095. {
  2096. return;
  2097. }
  2098. static void mv_setup_ifcfg(void __iomem *port_mmio, int want_gen2i)
  2099. {
  2100. u32 ifcfg = readl(port_mmio + SATA_INTERFACE_CFG_OFS);
  2101. ifcfg = (ifcfg & 0xf7f) | 0x9b1000; /* from chip spec */
  2102. if (want_gen2i)
  2103. ifcfg |= (1 << 7); /* enable gen2i speed */
  2104. writelfl(ifcfg, port_mmio + SATA_INTERFACE_CFG_OFS);
  2105. }
  2106. static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio,
  2107. unsigned int port_no)
  2108. {
  2109. void __iomem *port_mmio = mv_port_base(mmio, port_no);
  2110. /*
  2111. * The datasheet warns against setting EDMA_RESET when EDMA is active
  2112. * (but doesn't say what the problem might be). So we first try
  2113. * to disable the EDMA engine before doing the EDMA_RESET operation.
  2114. */
  2115. mv_stop_edma_engine(port_mmio);
  2116. writelfl(EDMA_RESET, port_mmio + EDMA_CMD_OFS);
  2117. if (!IS_GEN_I(hpriv)) {
  2118. /* Enable 3.0gb/s link speed: this survives EDMA_RESET */
  2119. mv_setup_ifcfg(port_mmio, 1);
  2120. }
  2121. /*
  2122. * Strobing EDMA_RESET here causes a hard reset of the SATA transport,
  2123. * link, and physical layers. It resets all SATA interface registers
  2124. * (except for SATA_INTERFACE_CFG), and issues a COMRESET to the dev.
  2125. */
  2126. writelfl(EDMA_RESET, port_mmio + EDMA_CMD_OFS);
  2127. udelay(25); /* allow reset propagation */
  2128. writelfl(0, port_mmio + EDMA_CMD_OFS);
  2129. hpriv->ops->phy_errata(hpriv, mmio, port_no);
  2130. if (IS_GEN_I(hpriv))
  2131. mdelay(1);
  2132. }
  2133. static void mv_pmp_select(struct ata_port *ap, int pmp)
  2134. {
  2135. if (sata_pmp_supported(ap)) {
  2136. void __iomem *port_mmio = mv_ap_base(ap);
  2137. u32 reg = readl(port_mmio + SATA_IFCTL_OFS);
  2138. int old = reg & 0xf;
  2139. if (old != pmp) {
  2140. reg = (reg & ~0xf) | pmp;
  2141. writelfl(reg, port_mmio + SATA_IFCTL_OFS);
  2142. }
  2143. }
  2144. }
  2145. static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class,
  2146. unsigned long deadline)
  2147. {
  2148. mv_pmp_select(link->ap, sata_srst_pmp(link));
  2149. return sata_std_hardreset(link, class, deadline);
  2150. }
  2151. static int mv_softreset(struct ata_link *link, unsigned int *class,
  2152. unsigned long deadline)
  2153. {
  2154. mv_pmp_select(link->ap, sata_srst_pmp(link));
  2155. return ata_sff_softreset(link, class, deadline);
  2156. }
  2157. static int mv_hardreset(struct ata_link *link, unsigned int *class,
  2158. unsigned long deadline)
  2159. {
  2160. struct ata_port *ap = link->ap;
  2161. struct mv_host_priv *hpriv = ap->host->private_data;
  2162. struct mv_port_priv *pp = ap->private_data;
  2163. void __iomem *mmio = hpriv->base;
  2164. int rc, attempts = 0, extra = 0;
  2165. u32 sstatus;
  2166. bool online;
  2167. mv_reset_channel(hpriv, mmio, ap->port_no);
  2168. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  2169. /* Workaround for errata FEr SATA#10 (part 2) */
  2170. do {
  2171. const unsigned long *timing =
  2172. sata_ehc_deb_timing(&link->eh_context);
  2173. rc = sata_link_hardreset(link, timing, deadline + extra,
  2174. &online, NULL);
  2175. if (rc)
  2176. return rc;
  2177. sata_scr_read(link, SCR_STATUS, &sstatus);
  2178. if (!IS_GEN_I(hpriv) && ++attempts >= 5 && sstatus == 0x121) {
  2179. /* Force 1.5gb/s link speed and try again */
  2180. mv_setup_ifcfg(mv_ap_base(ap), 0);
  2181. if (time_after(jiffies + HZ, deadline))
  2182. extra = HZ; /* only extend it once, max */
  2183. }
  2184. } while (sstatus != 0x0 && sstatus != 0x113 && sstatus != 0x123);
  2185. return rc;
  2186. }
  2187. static void mv_eh_freeze(struct ata_port *ap)
  2188. {
  2189. struct mv_host_priv *hpriv = ap->host->private_data;
  2190. unsigned int shift, hardport, port = ap->port_no;
  2191. u32 main_irq_mask;
  2192. /* FIXME: handle coalescing completion events properly */
  2193. mv_stop_edma(ap);
  2194. MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
  2195. /* disable assertion of portN err, done events */
  2196. main_irq_mask = readl(hpriv->main_irq_mask_addr);
  2197. main_irq_mask &= ~((DONE_IRQ | ERR_IRQ) << shift);
  2198. writelfl(main_irq_mask, hpriv->main_irq_mask_addr);
  2199. }
  2200. static void mv_eh_thaw(struct ata_port *ap)
  2201. {
  2202. struct mv_host_priv *hpriv = ap->host->private_data;
  2203. unsigned int shift, hardport, port = ap->port_no;
  2204. void __iomem *hc_mmio = mv_hc_base_from_port(hpriv->base, port);
  2205. void __iomem *port_mmio = mv_ap_base(ap);
  2206. u32 main_irq_mask, hc_irq_cause;
  2207. /* FIXME: handle coalescing completion events properly */
  2208. MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport);
  2209. /* clear EDMA errors on this port */
  2210. writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  2211. /* clear pending irq events */
  2212. hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
  2213. hc_irq_cause &= ~((DEV_IRQ | DMA_IRQ) << hardport);
  2214. writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
  2215. /* enable assertion of portN err, done events */
  2216. main_irq_mask = readl(hpriv->main_irq_mask_addr);
  2217. main_irq_mask |= ((DONE_IRQ | ERR_IRQ) << shift);
  2218. writelfl(main_irq_mask, hpriv->main_irq_mask_addr);
  2219. }
  2220. /**
  2221. * mv_port_init - Perform some early initialization on a single port.
  2222. * @port: libata data structure storing shadow register addresses
  2223. * @port_mmio: base address of the port
  2224. *
  2225. * Initialize shadow register mmio addresses, clear outstanding
  2226. * interrupts on the port, and unmask interrupts for the future
  2227. * start of the port.
  2228. *
  2229. * LOCKING:
  2230. * Inherited from caller.
  2231. */
  2232. static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
  2233. {
  2234. void __iomem *shd_base = port_mmio + SHD_BLK_OFS;
  2235. unsigned serr_ofs;
  2236. /* PIO related setup
  2237. */
  2238. port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
  2239. port->error_addr =
  2240. port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
  2241. port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
  2242. port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
  2243. port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
  2244. port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
  2245. port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
  2246. port->status_addr =
  2247. port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
  2248. /* special case: control/altstatus doesn't have ATA_REG_ address */
  2249. port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
  2250. /* unused: */
  2251. port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
  2252. /* Clear any currently outstanding port interrupt conditions */
  2253. serr_ofs = mv_scr_offset(SCR_ERROR);
  2254. writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
  2255. writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  2256. /* unmask all non-transient EDMA error interrupts */
  2257. writelfl(~EDMA_ERR_IRQ_TRANSIENT, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
  2258. VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
  2259. readl(port_mmio + EDMA_CFG_OFS),
  2260. readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
  2261. readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
  2262. }
  2263. static unsigned int mv_in_pcix_mode(struct ata_host *host)
  2264. {
  2265. struct mv_host_priv *hpriv = host->private_data;
  2266. void __iomem *mmio = hpriv->base;
  2267. u32 reg;
  2268. if (!HAS_PCI(host) || !IS_PCIE(hpriv))
  2269. return 0; /* not PCI-X capable */
  2270. reg = readl(mmio + MV_PCI_MODE_OFS);
  2271. if ((reg & MV_PCI_MODE_MASK) == 0)
  2272. return 0; /* conventional PCI mode */
  2273. return 1; /* chip is in PCI-X mode */
  2274. }
  2275. static int mv_pci_cut_through_okay(struct ata_host *host)
  2276. {
  2277. struct mv_host_priv *hpriv = host->private_data;
  2278. void __iomem *mmio = hpriv->base;
  2279. u32 reg;
  2280. if (!mv_in_pcix_mode(host)) {
  2281. reg = readl(mmio + PCI_COMMAND_OFS);
  2282. if (reg & PCI_COMMAND_MRDTRIG)
  2283. return 0; /* not okay */
  2284. }
  2285. return 1; /* okay */
  2286. }
  2287. static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
  2288. {
  2289. struct pci_dev *pdev = to_pci_dev(host->dev);
  2290. struct mv_host_priv *hpriv = host->private_data;
  2291. u32 hp_flags = hpriv->hp_flags;
  2292. switch (board_idx) {
  2293. case chip_5080:
  2294. hpriv->ops = &mv5xxx_ops;
  2295. hp_flags |= MV_HP_GEN_I;
  2296. switch (pdev->revision) {
  2297. case 0x1:
  2298. hp_flags |= MV_HP_ERRATA_50XXB0;
  2299. break;
  2300. case 0x3:
  2301. hp_flags |= MV_HP_ERRATA_50XXB2;
  2302. break;
  2303. default:
  2304. dev_printk(KERN_WARNING, &pdev->dev,
  2305. "Applying 50XXB2 workarounds to unknown rev\n");
  2306. hp_flags |= MV_HP_ERRATA_50XXB2;
  2307. break;
  2308. }
  2309. break;
  2310. case chip_504x:
  2311. case chip_508x:
  2312. hpriv->ops = &mv5xxx_ops;
  2313. hp_flags |= MV_HP_GEN_I;
  2314. switch (pdev->revision) {
  2315. case 0x0:
  2316. hp_flags |= MV_HP_ERRATA_50XXB0;
  2317. break;
  2318. case 0x3:
  2319. hp_flags |= MV_HP_ERRATA_50XXB2;
  2320. break;
  2321. default:
  2322. dev_printk(KERN_WARNING, &pdev->dev,
  2323. "Applying B2 workarounds to unknown rev\n");
  2324. hp_flags |= MV_HP_ERRATA_50XXB2;
  2325. break;
  2326. }
  2327. break;
  2328. case chip_604x:
  2329. case chip_608x:
  2330. hpriv->ops = &mv6xxx_ops;
  2331. hp_flags |= MV_HP_GEN_II;
  2332. switch (pdev->revision) {
  2333. case 0x7:
  2334. hp_flags |= MV_HP_ERRATA_60X1B2;
  2335. break;
  2336. case 0x9:
  2337. hp_flags |= MV_HP_ERRATA_60X1C0;
  2338. break;
  2339. default:
  2340. dev_printk(KERN_WARNING, &pdev->dev,
  2341. "Applying B2 workarounds to unknown rev\n");
  2342. hp_flags |= MV_HP_ERRATA_60X1B2;
  2343. break;
  2344. }
  2345. break;
  2346. case chip_7042:
  2347. hp_flags |= MV_HP_PCIE | MV_HP_CUT_THROUGH;
  2348. if (pdev->vendor == PCI_VENDOR_ID_TTI &&
  2349. (pdev->device == 0x2300 || pdev->device == 0x2310))
  2350. {
  2351. /*
  2352. * Highpoint RocketRAID PCIe 23xx series cards:
  2353. *
  2354. * Unconfigured drives are treated as "Legacy"
  2355. * by the BIOS, and it overwrites sector 8 with
  2356. * a "Lgcy" metadata block prior to Linux boot.
  2357. *
  2358. * Configured drives (RAID or JBOD) leave sector 8
  2359. * alone, but instead overwrite a high numbered
  2360. * sector for the RAID metadata. This sector can
  2361. * be determined exactly, by truncating the physical
  2362. * drive capacity to a nice even GB value.
  2363. *
  2364. * RAID metadata is at: (dev->n_sectors & ~0xfffff)
  2365. *
  2366. * Warn the user, lest they think we're just buggy.
  2367. */
  2368. printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID"
  2369. " BIOS CORRUPTS DATA on all attached drives,"
  2370. " regardless of if/how they are configured."
  2371. " BEWARE!\n");
  2372. printk(KERN_WARNING DRV_NAME ": For data safety, do not"
  2373. " use sectors 8-9 on \"Legacy\" drives,"
  2374. " and avoid the final two gigabytes on"
  2375. " all RocketRAID BIOS initialized drives.\n");
  2376. }
  2377. /* drop through */
  2378. case chip_6042:
  2379. hpriv->ops = &mv6xxx_ops;
  2380. hp_flags |= MV_HP_GEN_IIE;
  2381. if (board_idx == chip_6042 && mv_pci_cut_through_okay(host))
  2382. hp_flags |= MV_HP_CUT_THROUGH;
  2383. switch (pdev->revision) {
  2384. case 0x0:
  2385. hp_flags |= MV_HP_ERRATA_XX42A0;
  2386. break;
  2387. case 0x1:
  2388. hp_flags |= MV_HP_ERRATA_60X1C0;
  2389. break;
  2390. default:
  2391. dev_printk(KERN_WARNING, &pdev->dev,
  2392. "Applying 60X1C0 workarounds to unknown rev\n");
  2393. hp_flags |= MV_HP_ERRATA_60X1C0;
  2394. break;
  2395. }
  2396. break;
  2397. case chip_soc:
  2398. hpriv->ops = &mv_soc_ops;
  2399. hp_flags |= MV_HP_ERRATA_60X1C0;
  2400. break;
  2401. default:
  2402. dev_printk(KERN_ERR, host->dev,
  2403. "BUG: invalid board index %u\n", board_idx);
  2404. return 1;
  2405. }
  2406. hpriv->hp_flags = hp_flags;
  2407. if (hp_flags & MV_HP_PCIE) {
  2408. hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS;
  2409. hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS;
  2410. hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS;
  2411. } else {
  2412. hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS;
  2413. hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS;
  2414. hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS;
  2415. }
  2416. return 0;
  2417. }
  2418. /**
  2419. * mv_init_host - Perform some early initialization of the host.
  2420. * @host: ATA host to initialize
  2421. * @board_idx: controller index
  2422. *
  2423. * If possible, do an early global reset of the host. Then do
  2424. * our port init and clear/unmask all/relevant host interrupts.
  2425. *
  2426. * LOCKING:
  2427. * Inherited from caller.
  2428. */
  2429. static int mv_init_host(struct ata_host *host, unsigned int board_idx)
  2430. {
  2431. int rc = 0, n_hc, port, hc;
  2432. struct mv_host_priv *hpriv = host->private_data;
  2433. void __iomem *mmio = hpriv->base;
  2434. rc = mv_chip_id(host, board_idx);
  2435. if (rc)
  2436. goto done;
  2437. if (HAS_PCI(host)) {
  2438. hpriv->main_irq_cause_addr = mmio + PCI_HC_MAIN_IRQ_CAUSE_OFS;
  2439. hpriv->main_irq_mask_addr = mmio + PCI_HC_MAIN_IRQ_MASK_OFS;
  2440. } else {
  2441. hpriv->main_irq_cause_addr = mmio + SOC_HC_MAIN_IRQ_CAUSE_OFS;
  2442. hpriv->main_irq_mask_addr = mmio + SOC_HC_MAIN_IRQ_MASK_OFS;
  2443. }
  2444. /* global interrupt mask: 0 == mask everything */
  2445. writel(0, hpriv->main_irq_mask_addr);
  2446. n_hc = mv_get_hc_count(host->ports[0]->flags);
  2447. for (port = 0; port < host->n_ports; port++)
  2448. hpriv->ops->read_preamp(hpriv, port, mmio);
  2449. rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
  2450. if (rc)
  2451. goto done;
  2452. hpriv->ops->reset_flash(hpriv, mmio);
  2453. hpriv->ops->reset_bus(host, mmio);
  2454. hpriv->ops->enable_leds(hpriv, mmio);
  2455. for (port = 0; port < host->n_ports; port++) {
  2456. struct ata_port *ap = host->ports[port];
  2457. void __iomem *port_mmio = mv_port_base(mmio, port);
  2458. mv_port_init(&ap->ioaddr, port_mmio);
  2459. #ifdef CONFIG_PCI
  2460. if (HAS_PCI(host)) {
  2461. unsigned int offset = port_mmio - mmio;
  2462. ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
  2463. ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
  2464. }
  2465. #endif
  2466. }
  2467. for (hc = 0; hc < n_hc; hc++) {
  2468. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  2469. VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
  2470. "(before clear)=0x%08x\n", hc,
  2471. readl(hc_mmio + HC_CFG_OFS),
  2472. readl(hc_mmio + HC_IRQ_CAUSE_OFS));
  2473. /* Clear any currently outstanding hc interrupt conditions */
  2474. writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
  2475. }
  2476. if (HAS_PCI(host)) {
  2477. /* Clear any currently outstanding host interrupt conditions */
  2478. writelfl(0, mmio + hpriv->irq_cause_ofs);
  2479. /* and unmask interrupt generation for host regs */
  2480. writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs);
  2481. if (IS_GEN_I(hpriv))
  2482. writelfl(~HC_MAIN_MASKED_IRQS_5,
  2483. hpriv->main_irq_mask_addr);
  2484. else
  2485. writelfl(~HC_MAIN_MASKED_IRQS,
  2486. hpriv->main_irq_mask_addr);
  2487. VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
  2488. "PCI int cause/mask=0x%08x/0x%08x\n",
  2489. readl(hpriv->main_irq_cause_addr),
  2490. readl(hpriv->main_irq_mask_addr),
  2491. readl(mmio + hpriv->irq_cause_ofs),
  2492. readl(mmio + hpriv->irq_mask_ofs));
  2493. } else {
  2494. writelfl(~HC_MAIN_MASKED_IRQS_SOC,
  2495. hpriv->main_irq_mask_addr);
  2496. VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x\n",
  2497. readl(hpriv->main_irq_cause_addr),
  2498. readl(hpriv->main_irq_mask_addr));
  2499. }
  2500. done:
  2501. return rc;
  2502. }
  2503. static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev)
  2504. {
  2505. hpriv->crqb_pool = dmam_pool_create("crqb_q", dev, MV_CRQB_Q_SZ,
  2506. MV_CRQB_Q_SZ, 0);
  2507. if (!hpriv->crqb_pool)
  2508. return -ENOMEM;
  2509. hpriv->crpb_pool = dmam_pool_create("crpb_q", dev, MV_CRPB_Q_SZ,
  2510. MV_CRPB_Q_SZ, 0);
  2511. if (!hpriv->crpb_pool)
  2512. return -ENOMEM;
  2513. hpriv->sg_tbl_pool = dmam_pool_create("sg_tbl", dev, MV_SG_TBL_SZ,
  2514. MV_SG_TBL_SZ, 0);
  2515. if (!hpriv->sg_tbl_pool)
  2516. return -ENOMEM;
  2517. return 0;
  2518. }
  2519. static void mv_conf_mbus_windows(struct mv_host_priv *hpriv,
  2520. struct mbus_dram_target_info *dram)
  2521. {
  2522. int i;
  2523. for (i = 0; i < 4; i++) {
  2524. writel(0, hpriv->base + WINDOW_CTRL(i));
  2525. writel(0, hpriv->base + WINDOW_BASE(i));
  2526. }
  2527. for (i = 0; i < dram->num_cs; i++) {
  2528. struct mbus_dram_window *cs = dram->cs + i;
  2529. writel(((cs->size - 1) & 0xffff0000) |
  2530. (cs->mbus_attr << 8) |
  2531. (dram->mbus_dram_target_id << 4) | 1,
  2532. hpriv->base + WINDOW_CTRL(i));
  2533. writel(cs->base, hpriv->base + WINDOW_BASE(i));
  2534. }
  2535. }
  2536. /**
  2537. * mv_platform_probe - handle a positive probe of an soc Marvell
  2538. * host
  2539. * @pdev: platform device found
  2540. *
  2541. * LOCKING:
  2542. * Inherited from caller.
  2543. */
  2544. static int mv_platform_probe(struct platform_device *pdev)
  2545. {
  2546. static int printed_version;
  2547. const struct mv_sata_platform_data *mv_platform_data;
  2548. const struct ata_port_info *ppi[] =
  2549. { &mv_port_info[chip_soc], NULL };
  2550. struct ata_host *host;
  2551. struct mv_host_priv *hpriv;
  2552. struct resource *res;
  2553. int n_ports, rc;
  2554. if (!printed_version++)
  2555. dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
  2556. /*
  2557. * Simple resource validation ..
  2558. */
  2559. if (unlikely(pdev->num_resources != 2)) {
  2560. dev_err(&pdev->dev, "invalid number of resources\n");
  2561. return -EINVAL;
  2562. }
  2563. /*
  2564. * Get the register base first
  2565. */
  2566. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2567. if (res == NULL)
  2568. return -EINVAL;
  2569. /* allocate host */
  2570. mv_platform_data = pdev->dev.platform_data;
  2571. n_ports = mv_platform_data->n_ports;
  2572. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  2573. hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
  2574. if (!host || !hpriv)
  2575. return -ENOMEM;
  2576. host->private_data = hpriv;
  2577. hpriv->n_ports = n_ports;
  2578. host->iomap = NULL;
  2579. hpriv->base = devm_ioremap(&pdev->dev, res->start,
  2580. res->end - res->start + 1);
  2581. hpriv->base -= MV_SATAHC0_REG_BASE;
  2582. /*
  2583. * (Re-)program MBUS remapping windows if we are asked to.
  2584. */
  2585. if (mv_platform_data->dram != NULL)
  2586. mv_conf_mbus_windows(hpriv, mv_platform_data->dram);
  2587. rc = mv_create_dma_pools(hpriv, &pdev->dev);
  2588. if (rc)
  2589. return rc;
  2590. /* initialize adapter */
  2591. rc = mv_init_host(host, chip_soc);
  2592. if (rc)
  2593. return rc;
  2594. dev_printk(KERN_INFO, &pdev->dev,
  2595. "slots %u ports %d\n", (unsigned)MV_MAX_Q_DEPTH,
  2596. host->n_ports);
  2597. return ata_host_activate(host, platform_get_irq(pdev, 0), mv_interrupt,
  2598. IRQF_SHARED, &mv6_sht);
  2599. }
  2600. /*
  2601. *
  2602. * mv_platform_remove - unplug a platform interface
  2603. * @pdev: platform device
  2604. *
  2605. * A platform bus SATA device has been unplugged. Perform the needed
  2606. * cleanup. Also called on module unload for any active devices.
  2607. */
  2608. static int __devexit mv_platform_remove(struct platform_device *pdev)
  2609. {
  2610. struct device *dev = &pdev->dev;
  2611. struct ata_host *host = dev_get_drvdata(dev);
  2612. ata_host_detach(host);
  2613. return 0;
  2614. }
  2615. static struct platform_driver mv_platform_driver = {
  2616. .probe = mv_platform_probe,
  2617. .remove = __devexit_p(mv_platform_remove),
  2618. .driver = {
  2619. .name = DRV_NAME,
  2620. .owner = THIS_MODULE,
  2621. },
  2622. };
  2623. #ifdef CONFIG_PCI
  2624. static int mv_pci_init_one(struct pci_dev *pdev,
  2625. const struct pci_device_id *ent);
  2626. static struct pci_driver mv_pci_driver = {
  2627. .name = DRV_NAME,
  2628. .id_table = mv_pci_tbl,
  2629. .probe = mv_pci_init_one,
  2630. .remove = ata_pci_remove_one,
  2631. };
  2632. /*
  2633. * module options
  2634. */
  2635. static int msi; /* Use PCI msi; either zero (off, default) or non-zero */
  2636. /* move to PCI layer or libata core? */
  2637. static int pci_go_64(struct pci_dev *pdev)
  2638. {
  2639. int rc;
  2640. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  2641. rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  2642. if (rc) {
  2643. rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  2644. if (rc) {
  2645. dev_printk(KERN_ERR, &pdev->dev,
  2646. "64-bit DMA enable failed\n");
  2647. return rc;
  2648. }
  2649. }
  2650. } else {
  2651. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  2652. if (rc) {
  2653. dev_printk(KERN_ERR, &pdev->dev,
  2654. "32-bit DMA enable failed\n");
  2655. return rc;
  2656. }
  2657. rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  2658. if (rc) {
  2659. dev_printk(KERN_ERR, &pdev->dev,
  2660. "32-bit consistent DMA enable failed\n");
  2661. return rc;
  2662. }
  2663. }
  2664. return rc;
  2665. }
  2666. /**
  2667. * mv_print_info - Dump key info to kernel log for perusal.
  2668. * @host: ATA host to print info about
  2669. *
  2670. * FIXME: complete this.
  2671. *
  2672. * LOCKING:
  2673. * Inherited from caller.
  2674. */
  2675. static void mv_print_info(struct ata_host *host)
  2676. {
  2677. struct pci_dev *pdev = to_pci_dev(host->dev);
  2678. struct mv_host_priv *hpriv = host->private_data;
  2679. u8 scc;
  2680. const char *scc_s, *gen;
  2681. /* Use this to determine the HW stepping of the chip so we know
  2682. * what errata to workaround
  2683. */
  2684. pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
  2685. if (scc == 0)
  2686. scc_s = "SCSI";
  2687. else if (scc == 0x01)
  2688. scc_s = "RAID";
  2689. else
  2690. scc_s = "?";
  2691. if (IS_GEN_I(hpriv))
  2692. gen = "I";
  2693. else if (IS_GEN_II(hpriv))
  2694. gen = "II";
  2695. else if (IS_GEN_IIE(hpriv))
  2696. gen = "IIE";
  2697. else
  2698. gen = "?";
  2699. dev_printk(KERN_INFO, &pdev->dev,
  2700. "Gen-%s %u slots %u ports %s mode IRQ via %s\n",
  2701. gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports,
  2702. scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
  2703. }
  2704. /**
  2705. * mv_pci_init_one - handle a positive probe of a PCI Marvell host
  2706. * @pdev: PCI device found
  2707. * @ent: PCI device ID entry for the matched host
  2708. *
  2709. * LOCKING:
  2710. * Inherited from caller.
  2711. */
  2712. static int mv_pci_init_one(struct pci_dev *pdev,
  2713. const struct pci_device_id *ent)
  2714. {
  2715. static int printed_version;
  2716. unsigned int board_idx = (unsigned int)ent->driver_data;
  2717. const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL };
  2718. struct ata_host *host;
  2719. struct mv_host_priv *hpriv;
  2720. int n_ports, rc;
  2721. if (!printed_version++)
  2722. dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
  2723. /* allocate host */
  2724. n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC;
  2725. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  2726. hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
  2727. if (!host || !hpriv)
  2728. return -ENOMEM;
  2729. host->private_data = hpriv;
  2730. hpriv->n_ports = n_ports;
  2731. /* acquire resources */
  2732. rc = pcim_enable_device(pdev);
  2733. if (rc)
  2734. return rc;
  2735. rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME);
  2736. if (rc == -EBUSY)
  2737. pcim_pin_device(pdev);
  2738. if (rc)
  2739. return rc;
  2740. host->iomap = pcim_iomap_table(pdev);
  2741. hpriv->base = host->iomap[MV_PRIMARY_BAR];
  2742. rc = pci_go_64(pdev);
  2743. if (rc)
  2744. return rc;
  2745. rc = mv_create_dma_pools(hpriv, &pdev->dev);
  2746. if (rc)
  2747. return rc;
  2748. /* initialize adapter */
  2749. rc = mv_init_host(host, board_idx);
  2750. if (rc)
  2751. return rc;
  2752. /* Enable interrupts */
  2753. if (msi && pci_enable_msi(pdev))
  2754. pci_intx(pdev, 1);
  2755. mv_dump_pci_cfg(pdev, 0x68);
  2756. mv_print_info(host);
  2757. pci_set_master(pdev);
  2758. pci_try_set_mwi(pdev);
  2759. return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED,
  2760. IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht);
  2761. }
  2762. #endif
  2763. static int mv_platform_probe(struct platform_device *pdev);
  2764. static int __devexit mv_platform_remove(struct platform_device *pdev);
  2765. static int __init mv_init(void)
  2766. {
  2767. int rc = -ENODEV;
  2768. #ifdef CONFIG_PCI
  2769. rc = pci_register_driver(&mv_pci_driver);
  2770. if (rc < 0)
  2771. return rc;
  2772. #endif
  2773. rc = platform_driver_register(&mv_platform_driver);
  2774. #ifdef CONFIG_PCI
  2775. if (rc < 0)
  2776. pci_unregister_driver(&mv_pci_driver);
  2777. #endif
  2778. return rc;
  2779. }
  2780. static void __exit mv_exit(void)
  2781. {
  2782. #ifdef CONFIG_PCI
  2783. pci_unregister_driver(&mv_pci_driver);
  2784. #endif
  2785. platform_driver_unregister(&mv_platform_driver);
  2786. }
  2787. MODULE_AUTHOR("Brett Russ");
  2788. MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
  2789. MODULE_LICENSE("GPL");
  2790. MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
  2791. MODULE_VERSION(DRV_VERSION);
  2792. MODULE_ALIAS("platform:" DRV_NAME);
  2793. #ifdef CONFIG_PCI
  2794. module_param(msi, int, 0444);
  2795. MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)");
  2796. #endif
  2797. module_init(mv_init);
  2798. module_exit(mv_exit);