sata_mv.c 100 KB

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