sata_mv.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796
  1. /*
  2. * sata_mv.c - Marvell SATA support
  3. *
  4. * Copyright 2005: EMC Corporation, all rights reserved.
  5. * Copyright 2005 Red Hat, Inc. All rights reserved.
  6. *
  7. * Please ALWAYS copy linux-ide@vger.kernel.org on emails.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. /*
  24. sata_mv TODO list:
  25. 1) Needs a full errata audit for all chipsets. I implemented most
  26. of the errata workarounds found in the Marvell vendor driver, but
  27. I distinctly remember a couple workarounds (one related to PCI-X)
  28. are still needed.
  29. 4) Add NCQ support (easy to intermediate, once new-EH support appears)
  30. 5) Investigate problems with PCI Message Signalled Interrupts (MSI).
  31. 6) Add port multiplier support (intermediate)
  32. 8) Develop a low-power-consumption strategy, and implement it.
  33. 9) [Experiment, low priority] See if ATAPI can be supported using
  34. "unknown FIS" or "vendor-specific FIS" support, or something creative
  35. like that.
  36. 10) [Experiment, low priority] Investigate interrupt coalescing.
  37. Quite often, especially with PCI Message Signalled Interrupts (MSI),
  38. the overhead reduced by interrupt mitigation is quite often not
  39. worth the latency cost.
  40. 11) [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. Target mode, for those without docs, is the ability to directly
  44. connect two SATA controllers.
  45. 13) Verify that 7042 is fully supported. I only have a 6042.
  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/dma-mapping.h>
  55. #include <linux/device.h>
  56. #include <scsi/scsi_host.h>
  57. #include <scsi/scsi_cmnd.h>
  58. #include <scsi/scsi_device.h>
  59. #include <linux/libata.h>
  60. #define DRV_NAME "sata_mv"
  61. #define DRV_VERSION "1.01"
  62. enum {
  63. /* BAR's are enumerated in terms of pci_resource_start() terms */
  64. MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */
  65. MV_IO_BAR = 2, /* offset 0x18: IO space */
  66. MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */
  67. MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
  68. MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
  69. MV_PCI_REG_BASE = 0,
  70. MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */
  71. MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08),
  72. MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88),
  73. MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c),
  74. MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc),
  75. MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0),
  76. MV_SATAHC0_REG_BASE = 0x20000,
  77. MV_FLASH_CTL = 0x1046c,
  78. MV_GPIO_PORT_CTL = 0x104f0,
  79. MV_RESET_CFG = 0x180d8,
  80. MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ,
  81. MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ,
  82. MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
  83. MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
  84. MV_MAX_Q_DEPTH = 32,
  85. MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
  86. /* CRQB needs alignment on a 1KB boundary. Size == 1KB
  87. * CRPB needs alignment on a 256B boundary. Size == 256B
  88. * SG count of 176 leads to MV_PORT_PRIV_DMA_SZ == 4KB
  89. * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B
  90. */
  91. MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH),
  92. MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH),
  93. MV_MAX_SG_CT = 176,
  94. MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
  95. MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ),
  96. MV_PORTS_PER_HC = 4,
  97. /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
  98. MV_PORT_HC_SHIFT = 2,
  99. /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */
  100. MV_PORT_MASK = 3,
  101. /* Host Flags */
  102. MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
  103. MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
  104. MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
  105. ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI |
  106. ATA_FLAG_PIO_POLLING,
  107. MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
  108. CRQB_FLAG_READ = (1 << 0),
  109. CRQB_TAG_SHIFT = 1,
  110. CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */
  111. CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */
  112. CRQB_CMD_ADDR_SHIFT = 8,
  113. CRQB_CMD_CS = (0x2 << 11),
  114. CRQB_CMD_LAST = (1 << 15),
  115. CRPB_FLAG_STATUS_SHIFT = 8,
  116. CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */
  117. CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */
  118. EPRD_FLAG_END_OF_TBL = (1 << 31),
  119. /* PCI interface registers */
  120. PCI_COMMAND_OFS = 0xc00,
  121. PCI_MAIN_CMD_STS_OFS = 0xd30,
  122. STOP_PCI_MASTER = (1 << 2),
  123. PCI_MASTER_EMPTY = (1 << 3),
  124. GLOB_SFT_RST = (1 << 4),
  125. MV_PCI_MODE = 0xd00,
  126. MV_PCI_EXP_ROM_BAR_CTL = 0xd2c,
  127. MV_PCI_DISC_TIMER = 0xd04,
  128. MV_PCI_MSI_TRIGGER = 0xc38,
  129. MV_PCI_SERR_MASK = 0xc28,
  130. MV_PCI_XBAR_TMOUT = 0x1d04,
  131. MV_PCI_ERR_LOW_ADDRESS = 0x1d40,
  132. MV_PCI_ERR_HIGH_ADDRESS = 0x1d44,
  133. MV_PCI_ERR_ATTRIBUTE = 0x1d48,
  134. MV_PCI_ERR_COMMAND = 0x1d50,
  135. PCI_IRQ_CAUSE_OFS = 0x1d58,
  136. PCI_IRQ_MASK_OFS = 0x1d5c,
  137. PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
  138. PCIE_IRQ_CAUSE_OFS = 0x1900,
  139. PCIE_IRQ_MASK_OFS = 0x1910,
  140. PCIE_UNMASK_ALL_IRQS = 0x70a, /* assorted bits */
  141. HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
  142. HC_MAIN_IRQ_MASK_OFS = 0x1d64,
  143. PORT0_ERR = (1 << 0), /* shift by port # */
  144. PORT0_DONE = (1 << 1), /* shift by port # */
  145. HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
  146. HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
  147. PCI_ERR = (1 << 18),
  148. TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
  149. TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
  150. PORTS_0_3_COAL_DONE = (1 << 8),
  151. PORTS_4_7_COAL_DONE = (1 << 17),
  152. PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
  153. GPIO_INT = (1 << 22),
  154. SELF_INT = (1 << 23),
  155. TWSI_INT = (1 << 24),
  156. HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
  157. HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */
  158. HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
  159. PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
  160. HC_MAIN_RSVD),
  161. HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
  162. HC_MAIN_RSVD_5),
  163. /* SATAHC registers */
  164. HC_CFG_OFS = 0,
  165. HC_IRQ_CAUSE_OFS = 0x14,
  166. CRPB_DMA_DONE = (1 << 0), /* shift by port # */
  167. HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
  168. DEV_IRQ = (1 << 8), /* shift by port # */
  169. /* Shadow block registers */
  170. SHD_BLK_OFS = 0x100,
  171. SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
  172. /* SATA registers */
  173. SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
  174. SATA_ACTIVE_OFS = 0x350,
  175. PHY_MODE3 = 0x310,
  176. PHY_MODE4 = 0x314,
  177. PHY_MODE2 = 0x330,
  178. MV5_PHY_MODE = 0x74,
  179. MV5_LT_MODE = 0x30,
  180. MV5_PHY_CTL = 0x0C,
  181. SATA_INTERFACE_CTL = 0x050,
  182. MV_M2_PREAMP_MASK = 0x7e0,
  183. /* Port registers */
  184. EDMA_CFG_OFS = 0,
  185. EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */
  186. EDMA_CFG_NCQ = (1 << 5),
  187. EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
  188. EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
  189. EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
  190. EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
  191. EDMA_ERR_IRQ_MASK_OFS = 0xc,
  192. EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */
  193. EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */
  194. EDMA_ERR_DEV = (1 << 2), /* device error */
  195. EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */
  196. EDMA_ERR_DEV_CON = (1 << 4), /* device connected */
  197. EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */
  198. EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */
  199. EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */
  200. EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */
  201. EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */
  202. EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */
  203. EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */
  204. EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */
  205. EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */
  206. EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */
  207. EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
  208. EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */
  209. EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */
  210. EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */
  211. EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */
  212. EDMA_ERR_OVERRUN_5 = (1 << 5),
  213. EDMA_ERR_UNDERRUN_5 = (1 << 6),
  214. EDMA_EH_FREEZE = EDMA_ERR_D_PAR |
  215. EDMA_ERR_PRD_PAR |
  216. EDMA_ERR_DEV_DCON |
  217. EDMA_ERR_DEV_CON |
  218. EDMA_ERR_SERR |
  219. EDMA_ERR_SELF_DIS |
  220. EDMA_ERR_CRQB_PAR |
  221. EDMA_ERR_CRPB_PAR |
  222. EDMA_ERR_INTRL_PAR |
  223. EDMA_ERR_IORDY |
  224. EDMA_ERR_LNK_CTRL_RX_2 |
  225. EDMA_ERR_LNK_DATA_RX |
  226. EDMA_ERR_LNK_DATA_TX |
  227. EDMA_ERR_TRANS_PROTO,
  228. EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR |
  229. EDMA_ERR_PRD_PAR |
  230. EDMA_ERR_DEV_DCON |
  231. EDMA_ERR_DEV_CON |
  232. EDMA_ERR_OVERRUN_5 |
  233. EDMA_ERR_UNDERRUN_5 |
  234. EDMA_ERR_SELF_DIS_5 |
  235. EDMA_ERR_CRQB_PAR |
  236. EDMA_ERR_CRPB_PAR |
  237. EDMA_ERR_INTRL_PAR |
  238. EDMA_ERR_IORDY,
  239. EDMA_REQ_Q_BASE_HI_OFS = 0x10,
  240. EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
  241. EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
  242. EDMA_REQ_Q_PTR_SHIFT = 5,
  243. EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
  244. EDMA_RSP_Q_IN_PTR_OFS = 0x20,
  245. EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
  246. EDMA_RSP_Q_PTR_SHIFT = 3,
  247. EDMA_CMD_OFS = 0x28, /* EDMA command register */
  248. EDMA_EN = (1 << 0), /* enable EDMA */
  249. EDMA_DS = (1 << 1), /* disable EDMA; self-negated */
  250. ATA_RST = (1 << 2), /* reset trans/link/phy */
  251. EDMA_IORDY_TMOUT = 0x34,
  252. EDMA_ARB_CFG = 0x38,
  253. /* Host private flags (hp_flags) */
  254. MV_HP_FLAG_MSI = (1 << 0),
  255. MV_HP_ERRATA_50XXB0 = (1 << 1),
  256. MV_HP_ERRATA_50XXB2 = (1 << 2),
  257. MV_HP_ERRATA_60X1B2 = (1 << 3),
  258. MV_HP_ERRATA_60X1C0 = (1 << 4),
  259. MV_HP_ERRATA_XX42A0 = (1 << 5),
  260. MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */
  261. MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */
  262. MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */
  263. MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */
  264. /* Port private flags (pp_flags) */
  265. MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
  266. MV_PP_FLAG_HAD_A_RESET = (1 << 2), /* 1st hard reset complete? */
  267. };
  268. #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I)
  269. #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II)
  270. #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
  271. enum {
  272. /* DMA boundary 0xffff is required by the s/g splitting
  273. * we need on /length/ in mv_fill-sg().
  274. */
  275. MV_DMA_BOUNDARY = 0xffffU,
  276. /* mask of register bits containing lower 32 bits
  277. * of EDMA request queue DMA address
  278. */
  279. EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
  280. /* ditto, for response queue */
  281. EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
  282. };
  283. enum chip_type {
  284. chip_504x,
  285. chip_508x,
  286. chip_5080,
  287. chip_604x,
  288. chip_608x,
  289. chip_6042,
  290. chip_7042,
  291. };
  292. /* Command ReQuest Block: 32B */
  293. struct mv_crqb {
  294. __le32 sg_addr;
  295. __le32 sg_addr_hi;
  296. __le16 ctrl_flags;
  297. __le16 ata_cmd[11];
  298. };
  299. struct mv_crqb_iie {
  300. __le32 addr;
  301. __le32 addr_hi;
  302. __le32 flags;
  303. __le32 len;
  304. __le32 ata_cmd[4];
  305. };
  306. /* Command ResPonse Block: 8B */
  307. struct mv_crpb {
  308. __le16 id;
  309. __le16 flags;
  310. __le32 tmstmp;
  311. };
  312. /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
  313. struct mv_sg {
  314. __le32 addr;
  315. __le32 flags_size;
  316. __le32 addr_hi;
  317. __le32 reserved;
  318. };
  319. struct mv_port_priv {
  320. struct mv_crqb *crqb;
  321. dma_addr_t crqb_dma;
  322. struct mv_crpb *crpb;
  323. dma_addr_t crpb_dma;
  324. struct mv_sg *sg_tbl;
  325. dma_addr_t sg_tbl_dma;
  326. unsigned int req_idx;
  327. unsigned int resp_idx;
  328. u32 pp_flags;
  329. };
  330. struct mv_port_signal {
  331. u32 amps;
  332. u32 pre;
  333. };
  334. struct mv_host_priv {
  335. u32 hp_flags;
  336. struct mv_port_signal signal[8];
  337. const struct mv_hw_ops *ops;
  338. u32 irq_cause_ofs;
  339. u32 irq_mask_ofs;
  340. u32 unmask_all_irqs;
  341. };
  342. struct mv_hw_ops {
  343. void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
  344. unsigned int port);
  345. void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio);
  346. void (*read_preamp)(struct mv_host_priv *hpriv, int idx,
  347. void __iomem *mmio);
  348. int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio,
  349. unsigned int n_hc);
  350. void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio);
  351. void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio);
  352. };
  353. static void mv_irq_clear(struct ata_port *ap);
  354. static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
  355. static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
  356. static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val);
  357. static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
  358. static int mv_port_start(struct ata_port *ap);
  359. static void mv_port_stop(struct ata_port *ap);
  360. static void mv_qc_prep(struct ata_queued_cmd *qc);
  361. static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
  362. static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
  363. static void mv_error_handler(struct ata_port *ap);
  364. static void mv_post_int_cmd(struct ata_queued_cmd *qc);
  365. static void mv_eh_freeze(struct ata_port *ap);
  366. static void mv_eh_thaw(struct ata_port *ap);
  367. static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
  368. static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  369. unsigned int port);
  370. static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
  371. static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
  372. void __iomem *mmio);
  373. static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  374. unsigned int n_hc);
  375. static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
  376. static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio);
  377. static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  378. unsigned int port);
  379. static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
  380. static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
  381. void __iomem *mmio);
  382. static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  383. unsigned int n_hc);
  384. static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
  385. static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio);
  386. static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
  387. unsigned int port_no);
  388. static struct scsi_host_template mv5_sht = {
  389. .module = THIS_MODULE,
  390. .name = DRV_NAME,
  391. .ioctl = ata_scsi_ioctl,
  392. .queuecommand = ata_scsi_queuecmd,
  393. .can_queue = ATA_DEF_QUEUE,
  394. .this_id = ATA_SHT_THIS_ID,
  395. .sg_tablesize = MV_MAX_SG_CT / 2,
  396. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  397. .emulated = ATA_SHT_EMULATED,
  398. .use_clustering = 1,
  399. .proc_name = DRV_NAME,
  400. .dma_boundary = MV_DMA_BOUNDARY,
  401. .slave_configure = ata_scsi_slave_config,
  402. .slave_destroy = ata_scsi_slave_destroy,
  403. .bios_param = ata_std_bios_param,
  404. };
  405. static struct scsi_host_template mv6_sht = {
  406. .module = THIS_MODULE,
  407. .name = DRV_NAME,
  408. .ioctl = ata_scsi_ioctl,
  409. .queuecommand = ata_scsi_queuecmd,
  410. .can_queue = ATA_DEF_QUEUE,
  411. .this_id = ATA_SHT_THIS_ID,
  412. .sg_tablesize = MV_MAX_SG_CT / 2,
  413. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  414. .emulated = ATA_SHT_EMULATED,
  415. .use_clustering = 1,
  416. .proc_name = DRV_NAME,
  417. .dma_boundary = MV_DMA_BOUNDARY,
  418. .slave_configure = ata_scsi_slave_config,
  419. .slave_destroy = ata_scsi_slave_destroy,
  420. .bios_param = ata_std_bios_param,
  421. };
  422. static const struct ata_port_operations mv5_ops = {
  423. .tf_load = ata_tf_load,
  424. .tf_read = ata_tf_read,
  425. .check_status = ata_check_status,
  426. .exec_command = ata_exec_command,
  427. .dev_select = ata_std_dev_select,
  428. .cable_detect = ata_cable_sata,
  429. .qc_prep = mv_qc_prep,
  430. .qc_issue = mv_qc_issue,
  431. .data_xfer = ata_data_xfer,
  432. .irq_clear = mv_irq_clear,
  433. .irq_on = ata_irq_on,
  434. .error_handler = mv_error_handler,
  435. .post_internal_cmd = mv_post_int_cmd,
  436. .freeze = mv_eh_freeze,
  437. .thaw = mv_eh_thaw,
  438. .scr_read = mv5_scr_read,
  439. .scr_write = mv5_scr_write,
  440. .port_start = mv_port_start,
  441. .port_stop = mv_port_stop,
  442. };
  443. static const struct ata_port_operations mv6_ops = {
  444. .tf_load = ata_tf_load,
  445. .tf_read = ata_tf_read,
  446. .check_status = ata_check_status,
  447. .exec_command = ata_exec_command,
  448. .dev_select = ata_std_dev_select,
  449. .cable_detect = ata_cable_sata,
  450. .qc_prep = mv_qc_prep,
  451. .qc_issue = mv_qc_issue,
  452. .data_xfer = ata_data_xfer,
  453. .irq_clear = mv_irq_clear,
  454. .irq_on = ata_irq_on,
  455. .error_handler = mv_error_handler,
  456. .post_internal_cmd = mv_post_int_cmd,
  457. .freeze = mv_eh_freeze,
  458. .thaw = mv_eh_thaw,
  459. .scr_read = mv_scr_read,
  460. .scr_write = mv_scr_write,
  461. .port_start = mv_port_start,
  462. .port_stop = mv_port_stop,
  463. };
  464. static const struct ata_port_operations mv_iie_ops = {
  465. .tf_load = ata_tf_load,
  466. .tf_read = ata_tf_read,
  467. .check_status = ata_check_status,
  468. .exec_command = ata_exec_command,
  469. .dev_select = ata_std_dev_select,
  470. .cable_detect = ata_cable_sata,
  471. .qc_prep = mv_qc_prep_iie,
  472. .qc_issue = mv_qc_issue,
  473. .data_xfer = ata_data_xfer,
  474. .irq_clear = mv_irq_clear,
  475. .irq_on = ata_irq_on,
  476. .error_handler = mv_error_handler,
  477. .post_internal_cmd = mv_post_int_cmd,
  478. .freeze = mv_eh_freeze,
  479. .thaw = mv_eh_thaw,
  480. .scr_read = mv_scr_read,
  481. .scr_write = mv_scr_write,
  482. .port_start = mv_port_start,
  483. .port_stop = mv_port_stop,
  484. };
  485. static const struct ata_port_info mv_port_info[] = {
  486. { /* chip_504x */
  487. .flags = MV_COMMON_FLAGS,
  488. .pio_mask = 0x1f, /* pio0-4 */
  489. .udma_mask = ATA_UDMA6,
  490. .port_ops = &mv5_ops,
  491. },
  492. { /* chip_508x */
  493. .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
  494. .pio_mask = 0x1f, /* pio0-4 */
  495. .udma_mask = ATA_UDMA6,
  496. .port_ops = &mv5_ops,
  497. },
  498. { /* chip_5080 */
  499. .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC,
  500. .pio_mask = 0x1f, /* pio0-4 */
  501. .udma_mask = ATA_UDMA6,
  502. .port_ops = &mv5_ops,
  503. },
  504. { /* chip_604x */
  505. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
  506. .pio_mask = 0x1f, /* pio0-4 */
  507. .udma_mask = ATA_UDMA6,
  508. .port_ops = &mv6_ops,
  509. },
  510. { /* chip_608x */
  511. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS |
  512. MV_FLAG_DUAL_HC,
  513. .pio_mask = 0x1f, /* pio0-4 */
  514. .udma_mask = ATA_UDMA6,
  515. .port_ops = &mv6_ops,
  516. },
  517. { /* chip_6042 */
  518. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
  519. .pio_mask = 0x1f, /* pio0-4 */
  520. .udma_mask = ATA_UDMA6,
  521. .port_ops = &mv_iie_ops,
  522. },
  523. { /* chip_7042 */
  524. .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS,
  525. .pio_mask = 0x1f, /* pio0-4 */
  526. .udma_mask = ATA_UDMA6,
  527. .port_ops = &mv_iie_ops,
  528. },
  529. };
  530. static const struct pci_device_id mv_pci_tbl[] = {
  531. { PCI_VDEVICE(MARVELL, 0x5040), chip_504x },
  532. { PCI_VDEVICE(MARVELL, 0x5041), chip_504x },
  533. { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 },
  534. { PCI_VDEVICE(MARVELL, 0x5081), chip_508x },
  535. /* RocketRAID 1740/174x have different identifiers */
  536. { PCI_VDEVICE(TTI, 0x1740), chip_508x },
  537. { PCI_VDEVICE(TTI, 0x1742), chip_508x },
  538. { PCI_VDEVICE(MARVELL, 0x6040), chip_604x },
  539. { PCI_VDEVICE(MARVELL, 0x6041), chip_604x },
  540. { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 },
  541. { PCI_VDEVICE(MARVELL, 0x6080), chip_608x },
  542. { PCI_VDEVICE(MARVELL, 0x6081), chip_608x },
  543. { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x },
  544. /* Adaptec 1430SA */
  545. { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 },
  546. /* Marvell 7042 support */
  547. { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 },
  548. /* Highpoint RocketRAID PCIe series */
  549. { PCI_VDEVICE(TTI, 0x2300), chip_7042 },
  550. { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
  551. { } /* terminate list */
  552. };
  553. static struct pci_driver mv_pci_driver = {
  554. .name = DRV_NAME,
  555. .id_table = mv_pci_tbl,
  556. .probe = mv_init_one,
  557. .remove = ata_pci_remove_one,
  558. };
  559. static const struct mv_hw_ops mv5xxx_ops = {
  560. .phy_errata = mv5_phy_errata,
  561. .enable_leds = mv5_enable_leds,
  562. .read_preamp = mv5_read_preamp,
  563. .reset_hc = mv5_reset_hc,
  564. .reset_flash = mv5_reset_flash,
  565. .reset_bus = mv5_reset_bus,
  566. };
  567. static const struct mv_hw_ops mv6xxx_ops = {
  568. .phy_errata = mv6_phy_errata,
  569. .enable_leds = mv6_enable_leds,
  570. .read_preamp = mv6_read_preamp,
  571. .reset_hc = mv6_reset_hc,
  572. .reset_flash = mv6_reset_flash,
  573. .reset_bus = mv_reset_pci_bus,
  574. };
  575. /*
  576. * module options
  577. */
  578. static int msi; /* Use PCI msi; either zero (off, default) or non-zero */
  579. /* move to PCI layer or libata core? */
  580. static int pci_go_64(struct pci_dev *pdev)
  581. {
  582. int rc;
  583. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  584. rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  585. if (rc) {
  586. rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  587. if (rc) {
  588. dev_printk(KERN_ERR, &pdev->dev,
  589. "64-bit DMA enable failed\n");
  590. return rc;
  591. }
  592. }
  593. } else {
  594. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  595. if (rc) {
  596. dev_printk(KERN_ERR, &pdev->dev,
  597. "32-bit DMA enable failed\n");
  598. return rc;
  599. }
  600. rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  601. if (rc) {
  602. dev_printk(KERN_ERR, &pdev->dev,
  603. "32-bit consistent DMA enable failed\n");
  604. return rc;
  605. }
  606. }
  607. return rc;
  608. }
  609. /*
  610. * Functions
  611. */
  612. static inline void writelfl(unsigned long data, void __iomem *addr)
  613. {
  614. writel(data, addr);
  615. (void) readl(addr); /* flush to avoid PCI posted write */
  616. }
  617. static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
  618. {
  619. return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
  620. }
  621. static inline unsigned int mv_hc_from_port(unsigned int port)
  622. {
  623. return port >> MV_PORT_HC_SHIFT;
  624. }
  625. static inline unsigned int mv_hardport_from_port(unsigned int port)
  626. {
  627. return port & MV_PORT_MASK;
  628. }
  629. static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
  630. unsigned int port)
  631. {
  632. return mv_hc_base(base, mv_hc_from_port(port));
  633. }
  634. static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
  635. {
  636. return mv_hc_base_from_port(base, port) +
  637. MV_SATAHC_ARBTR_REG_SZ +
  638. (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
  639. }
  640. static inline void __iomem *mv_ap_base(struct ata_port *ap)
  641. {
  642. return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no);
  643. }
  644. static inline int mv_get_hc_count(unsigned long port_flags)
  645. {
  646. return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
  647. }
  648. static void mv_irq_clear(struct ata_port *ap)
  649. {
  650. }
  651. static void mv_set_edma_ptrs(void __iomem *port_mmio,
  652. struct mv_host_priv *hpriv,
  653. struct mv_port_priv *pp)
  654. {
  655. u32 index;
  656. /*
  657. * initialize request queue
  658. */
  659. index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT;
  660. WARN_ON(pp->crqb_dma & 0x3ff);
  661. writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
  662. writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index,
  663. port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
  664. if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
  665. writelfl((pp->crqb_dma & 0xffffffff) | index,
  666. port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
  667. else
  668. writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
  669. /*
  670. * initialize response queue
  671. */
  672. index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT;
  673. WARN_ON(pp->crpb_dma & 0xff);
  674. writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
  675. if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
  676. writelfl((pp->crpb_dma & 0xffffffff) | index,
  677. port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
  678. else
  679. writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
  680. writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index,
  681. port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  682. }
  683. /**
  684. * mv_start_dma - Enable eDMA engine
  685. * @base: port base address
  686. * @pp: port private data
  687. *
  688. * Verify the local cache of the eDMA state is accurate with a
  689. * WARN_ON.
  690. *
  691. * LOCKING:
  692. * Inherited from caller.
  693. */
  694. static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv,
  695. struct mv_port_priv *pp)
  696. {
  697. if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
  698. /* clear EDMA event indicators, if any */
  699. writelfl(0, base + EDMA_ERR_IRQ_CAUSE_OFS);
  700. mv_set_edma_ptrs(base, hpriv, pp);
  701. writelfl(EDMA_EN, base + EDMA_CMD_OFS);
  702. pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
  703. }
  704. WARN_ON(!(EDMA_EN & readl(base + EDMA_CMD_OFS)));
  705. }
  706. /**
  707. * __mv_stop_dma - Disable eDMA engine
  708. * @ap: ATA channel to manipulate
  709. *
  710. * Verify the local cache of the eDMA state is accurate with a
  711. * WARN_ON.
  712. *
  713. * LOCKING:
  714. * Inherited from caller.
  715. */
  716. static int __mv_stop_dma(struct ata_port *ap)
  717. {
  718. void __iomem *port_mmio = mv_ap_base(ap);
  719. struct mv_port_priv *pp = ap->private_data;
  720. u32 reg;
  721. int i, err = 0;
  722. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
  723. /* Disable EDMA if active. The disable bit auto clears.
  724. */
  725. writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
  726. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  727. } else {
  728. WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS));
  729. }
  730. /* now properly wait for the eDMA to stop */
  731. for (i = 1000; i > 0; i--) {
  732. reg = readl(port_mmio + EDMA_CMD_OFS);
  733. if (!(reg & EDMA_EN))
  734. break;
  735. udelay(100);
  736. }
  737. if (reg & EDMA_EN) {
  738. ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n");
  739. err = -EIO;
  740. }
  741. return err;
  742. }
  743. static int mv_stop_dma(struct ata_port *ap)
  744. {
  745. unsigned long flags;
  746. int rc;
  747. spin_lock_irqsave(&ap->host->lock, flags);
  748. rc = __mv_stop_dma(ap);
  749. spin_unlock_irqrestore(&ap->host->lock, flags);
  750. return rc;
  751. }
  752. #ifdef ATA_DEBUG
  753. static void mv_dump_mem(void __iomem *start, unsigned bytes)
  754. {
  755. int b, w;
  756. for (b = 0; b < bytes; ) {
  757. DPRINTK("%p: ", start + b);
  758. for (w = 0; b < bytes && w < 4; w++) {
  759. printk("%08x ", readl(start + b));
  760. b += sizeof(u32);
  761. }
  762. printk("\n");
  763. }
  764. }
  765. #endif
  766. static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
  767. {
  768. #ifdef ATA_DEBUG
  769. int b, w;
  770. u32 dw;
  771. for (b = 0; b < bytes; ) {
  772. DPRINTK("%02x: ", b);
  773. for (w = 0; b < bytes && w < 4; w++) {
  774. (void) pci_read_config_dword(pdev, b, &dw);
  775. printk("%08x ", dw);
  776. b += sizeof(u32);
  777. }
  778. printk("\n");
  779. }
  780. #endif
  781. }
  782. static void mv_dump_all_regs(void __iomem *mmio_base, int port,
  783. struct pci_dev *pdev)
  784. {
  785. #ifdef ATA_DEBUG
  786. void __iomem *hc_base = mv_hc_base(mmio_base,
  787. port >> MV_PORT_HC_SHIFT);
  788. void __iomem *port_base;
  789. int start_port, num_ports, p, start_hc, num_hcs, hc;
  790. if (0 > port) {
  791. start_hc = start_port = 0;
  792. num_ports = 8; /* shld be benign for 4 port devs */
  793. num_hcs = 2;
  794. } else {
  795. start_hc = port >> MV_PORT_HC_SHIFT;
  796. start_port = port;
  797. num_ports = num_hcs = 1;
  798. }
  799. DPRINTK("All registers for port(s) %u-%u:\n", start_port,
  800. num_ports > 1 ? num_ports - 1 : start_port);
  801. if (NULL != pdev) {
  802. DPRINTK("PCI config space regs:\n");
  803. mv_dump_pci_cfg(pdev, 0x68);
  804. }
  805. DPRINTK("PCI regs:\n");
  806. mv_dump_mem(mmio_base+0xc00, 0x3c);
  807. mv_dump_mem(mmio_base+0xd00, 0x34);
  808. mv_dump_mem(mmio_base+0xf00, 0x4);
  809. mv_dump_mem(mmio_base+0x1d00, 0x6c);
  810. for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
  811. hc_base = mv_hc_base(mmio_base, hc);
  812. DPRINTK("HC regs (HC %i):\n", hc);
  813. mv_dump_mem(hc_base, 0x1c);
  814. }
  815. for (p = start_port; p < start_port + num_ports; p++) {
  816. port_base = mv_port_base(mmio_base, p);
  817. DPRINTK("EDMA regs (port %i):\n", p);
  818. mv_dump_mem(port_base, 0x54);
  819. DPRINTK("SATA regs (port %i):\n", p);
  820. mv_dump_mem(port_base+0x300, 0x60);
  821. }
  822. #endif
  823. }
  824. static unsigned int mv_scr_offset(unsigned int sc_reg_in)
  825. {
  826. unsigned int ofs;
  827. switch (sc_reg_in) {
  828. case SCR_STATUS:
  829. case SCR_CONTROL:
  830. case SCR_ERROR:
  831. ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
  832. break;
  833. case SCR_ACTIVE:
  834. ofs = SATA_ACTIVE_OFS; /* active is not with the others */
  835. break;
  836. default:
  837. ofs = 0xffffffffU;
  838. break;
  839. }
  840. return ofs;
  841. }
  842. static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
  843. {
  844. unsigned int ofs = mv_scr_offset(sc_reg_in);
  845. if (ofs != 0xffffffffU) {
  846. *val = readl(mv_ap_base(ap) + ofs);
  847. return 0;
  848. } else
  849. return -EINVAL;
  850. }
  851. static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
  852. {
  853. unsigned int ofs = mv_scr_offset(sc_reg_in);
  854. if (ofs != 0xffffffffU) {
  855. writelfl(val, mv_ap_base(ap) + ofs);
  856. return 0;
  857. } else
  858. return -EINVAL;
  859. }
  860. static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv,
  861. void __iomem *port_mmio)
  862. {
  863. u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
  864. /* set up non-NCQ EDMA configuration */
  865. cfg &= ~(1 << 9); /* disable eQue */
  866. if (IS_GEN_I(hpriv)) {
  867. cfg &= ~0x1f; /* clear queue depth */
  868. cfg |= (1 << 8); /* enab config burst size mask */
  869. }
  870. else if (IS_GEN_II(hpriv)) {
  871. cfg &= ~0x1f; /* clear queue depth */
  872. cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN;
  873. cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */
  874. }
  875. else if (IS_GEN_IIE(hpriv)) {
  876. cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */
  877. cfg |= (1 << 22); /* enab 4-entry host queue cache */
  878. cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */
  879. cfg |= (1 << 18); /* enab early completion */
  880. cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */
  881. cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */
  882. cfg &= ~(EDMA_CFG_NCQ); /* clear NCQ */
  883. }
  884. writelfl(cfg, port_mmio + EDMA_CFG_OFS);
  885. }
  886. /**
  887. * mv_port_start - Port specific init/start routine.
  888. * @ap: ATA channel to manipulate
  889. *
  890. * Allocate and point to DMA memory, init port private memory,
  891. * zero indices.
  892. *
  893. * LOCKING:
  894. * Inherited from caller.
  895. */
  896. static int mv_port_start(struct ata_port *ap)
  897. {
  898. struct device *dev = ap->host->dev;
  899. struct mv_host_priv *hpriv = ap->host->private_data;
  900. struct mv_port_priv *pp;
  901. void __iomem *port_mmio = mv_ap_base(ap);
  902. void *mem;
  903. dma_addr_t mem_dma;
  904. unsigned long flags;
  905. int rc;
  906. pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  907. if (!pp)
  908. return -ENOMEM;
  909. mem = dmam_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
  910. GFP_KERNEL);
  911. if (!mem)
  912. return -ENOMEM;
  913. memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
  914. rc = ata_pad_alloc(ap, dev);
  915. if (rc)
  916. return rc;
  917. /* First item in chunk of DMA memory:
  918. * 32-slot command request table (CRQB), 32 bytes each in size
  919. */
  920. pp->crqb = mem;
  921. pp->crqb_dma = mem_dma;
  922. mem += MV_CRQB_Q_SZ;
  923. mem_dma += MV_CRQB_Q_SZ;
  924. /* Second item:
  925. * 32-slot command response table (CRPB), 8 bytes each in size
  926. */
  927. pp->crpb = mem;
  928. pp->crpb_dma = mem_dma;
  929. mem += MV_CRPB_Q_SZ;
  930. mem_dma += MV_CRPB_Q_SZ;
  931. /* Third item:
  932. * Table of scatter-gather descriptors (ePRD), 16 bytes each
  933. */
  934. pp->sg_tbl = mem;
  935. pp->sg_tbl_dma = mem_dma;
  936. spin_lock_irqsave(&ap->host->lock, flags);
  937. mv_edma_cfg(ap, hpriv, port_mmio);
  938. mv_set_edma_ptrs(port_mmio, hpriv, pp);
  939. spin_unlock_irqrestore(&ap->host->lock, flags);
  940. /* Don't turn on EDMA here...do it before DMA commands only. Else
  941. * we'll be unable to send non-data, PIO, etc due to restricted access
  942. * to shadow regs.
  943. */
  944. ap->private_data = pp;
  945. return 0;
  946. }
  947. /**
  948. * mv_port_stop - Port specific cleanup/stop routine.
  949. * @ap: ATA channel to manipulate
  950. *
  951. * Stop DMA, cleanup port memory.
  952. *
  953. * LOCKING:
  954. * This routine uses the host lock to protect the DMA stop.
  955. */
  956. static void mv_port_stop(struct ata_port *ap)
  957. {
  958. mv_stop_dma(ap);
  959. }
  960. /**
  961. * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
  962. * @qc: queued command whose SG list to source from
  963. *
  964. * Populate the SG list and mark the last entry.
  965. *
  966. * LOCKING:
  967. * Inherited from caller.
  968. */
  969. static void mv_fill_sg(struct ata_queued_cmd *qc)
  970. {
  971. struct mv_port_priv *pp = qc->ap->private_data;
  972. struct scatterlist *sg;
  973. struct mv_sg *mv_sg, *last_sg = NULL;
  974. unsigned int si;
  975. mv_sg = pp->sg_tbl;
  976. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  977. dma_addr_t addr = sg_dma_address(sg);
  978. u32 sg_len = sg_dma_len(sg);
  979. while (sg_len) {
  980. u32 offset = addr & 0xffff;
  981. u32 len = sg_len;
  982. if ((offset + sg_len > 0x10000))
  983. len = 0x10000 - offset;
  984. mv_sg->addr = cpu_to_le32(addr & 0xffffffff);
  985. mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
  986. mv_sg->flags_size = cpu_to_le32(len & 0xffff);
  987. sg_len -= len;
  988. addr += len;
  989. last_sg = mv_sg;
  990. mv_sg++;
  991. }
  992. }
  993. if (likely(last_sg))
  994. last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
  995. }
  996. static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
  997. {
  998. u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
  999. (last ? CRQB_CMD_LAST : 0);
  1000. *cmdw = cpu_to_le16(tmp);
  1001. }
  1002. /**
  1003. * mv_qc_prep - Host specific command preparation.
  1004. * @qc: queued command to prepare
  1005. *
  1006. * This routine simply redirects to the general purpose routine
  1007. * if command is not DMA. Else, it handles prep of the CRQB
  1008. * (command request block), does some sanity checking, and calls
  1009. * the SG load routine.
  1010. *
  1011. * LOCKING:
  1012. * Inherited from caller.
  1013. */
  1014. static void mv_qc_prep(struct ata_queued_cmd *qc)
  1015. {
  1016. struct ata_port *ap = qc->ap;
  1017. struct mv_port_priv *pp = ap->private_data;
  1018. __le16 *cw;
  1019. struct ata_taskfile *tf;
  1020. u16 flags = 0;
  1021. unsigned in_index;
  1022. if (qc->tf.protocol != ATA_PROT_DMA)
  1023. return;
  1024. /* Fill in command request block
  1025. */
  1026. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  1027. flags |= CRQB_FLAG_READ;
  1028. WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
  1029. flags |= qc->tag << CRQB_TAG_SHIFT;
  1030. flags |= qc->tag << CRQB_IOID_SHIFT; /* 50xx appears to ignore this*/
  1031. /* get current queue index from software */
  1032. in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
  1033. pp->crqb[in_index].sg_addr =
  1034. cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
  1035. pp->crqb[in_index].sg_addr_hi =
  1036. cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
  1037. pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags);
  1038. cw = &pp->crqb[in_index].ata_cmd[0];
  1039. tf = &qc->tf;
  1040. /* Sadly, the CRQB cannot accomodate all registers--there are
  1041. * only 11 bytes...so we must pick and choose required
  1042. * registers based on the command. So, we drop feature and
  1043. * hob_feature for [RW] DMA commands, but they are needed for
  1044. * NCQ. NCQ will drop hob_nsect.
  1045. */
  1046. switch (tf->command) {
  1047. case ATA_CMD_READ:
  1048. case ATA_CMD_READ_EXT:
  1049. case ATA_CMD_WRITE:
  1050. case ATA_CMD_WRITE_EXT:
  1051. case ATA_CMD_WRITE_FUA_EXT:
  1052. mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
  1053. break;
  1054. #ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */
  1055. case ATA_CMD_FPDMA_READ:
  1056. case ATA_CMD_FPDMA_WRITE:
  1057. mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
  1058. mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
  1059. break;
  1060. #endif /* FIXME: remove this line when NCQ added */
  1061. default:
  1062. /* The only other commands EDMA supports in non-queued and
  1063. * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
  1064. * of which are defined/used by Linux. If we get here, this
  1065. * driver needs work.
  1066. *
  1067. * FIXME: modify libata to give qc_prep a return value and
  1068. * return error here.
  1069. */
  1070. BUG_ON(tf->command);
  1071. break;
  1072. }
  1073. mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
  1074. mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
  1075. mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
  1076. mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
  1077. mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
  1078. mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
  1079. mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
  1080. mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
  1081. mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
  1082. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  1083. return;
  1084. mv_fill_sg(qc);
  1085. }
  1086. /**
  1087. * mv_qc_prep_iie - Host specific command preparation.
  1088. * @qc: queued command to prepare
  1089. *
  1090. * This routine simply redirects to the general purpose routine
  1091. * if command is not DMA. Else, it handles prep of the CRQB
  1092. * (command request block), does some sanity checking, and calls
  1093. * the SG load routine.
  1094. *
  1095. * LOCKING:
  1096. * Inherited from caller.
  1097. */
  1098. static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
  1099. {
  1100. struct ata_port *ap = qc->ap;
  1101. struct mv_port_priv *pp = ap->private_data;
  1102. struct mv_crqb_iie *crqb;
  1103. struct ata_taskfile *tf;
  1104. unsigned in_index;
  1105. u32 flags = 0;
  1106. if (qc->tf.protocol != ATA_PROT_DMA)
  1107. return;
  1108. /* Fill in Gen IIE command request block
  1109. */
  1110. if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  1111. flags |= CRQB_FLAG_READ;
  1112. WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
  1113. flags |= qc->tag << CRQB_TAG_SHIFT;
  1114. flags |= qc->tag << CRQB_IOID_SHIFT; /* "I/O Id" is -really-
  1115. what we use as our tag */
  1116. /* get current queue index from software */
  1117. in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
  1118. crqb = (struct mv_crqb_iie *) &pp->crqb[in_index];
  1119. crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
  1120. crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
  1121. crqb->flags = cpu_to_le32(flags);
  1122. tf = &qc->tf;
  1123. crqb->ata_cmd[0] = cpu_to_le32(
  1124. (tf->command << 16) |
  1125. (tf->feature << 24)
  1126. );
  1127. crqb->ata_cmd[1] = cpu_to_le32(
  1128. (tf->lbal << 0) |
  1129. (tf->lbam << 8) |
  1130. (tf->lbah << 16) |
  1131. (tf->device << 24)
  1132. );
  1133. crqb->ata_cmd[2] = cpu_to_le32(
  1134. (tf->hob_lbal << 0) |
  1135. (tf->hob_lbam << 8) |
  1136. (tf->hob_lbah << 16) |
  1137. (tf->hob_feature << 24)
  1138. );
  1139. crqb->ata_cmd[3] = cpu_to_le32(
  1140. (tf->nsect << 0) |
  1141. (tf->hob_nsect << 8)
  1142. );
  1143. if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  1144. return;
  1145. mv_fill_sg(qc);
  1146. }
  1147. /**
  1148. * mv_qc_issue - Initiate a command to the host
  1149. * @qc: queued command to start
  1150. *
  1151. * This routine simply redirects to the general purpose routine
  1152. * if command is not DMA. Else, it sanity checks our local
  1153. * caches of the request producer/consumer indices then enables
  1154. * DMA and bumps the request producer index.
  1155. *
  1156. * LOCKING:
  1157. * Inherited from caller.
  1158. */
  1159. static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
  1160. {
  1161. struct ata_port *ap = qc->ap;
  1162. void __iomem *port_mmio = mv_ap_base(ap);
  1163. struct mv_port_priv *pp = ap->private_data;
  1164. struct mv_host_priv *hpriv = ap->host->private_data;
  1165. u32 in_index;
  1166. if (qc->tf.protocol != ATA_PROT_DMA) {
  1167. /* We're about to send a non-EDMA capable command to the
  1168. * port. Turn off EDMA so there won't be problems accessing
  1169. * shadow block, etc registers.
  1170. */
  1171. __mv_stop_dma(ap);
  1172. return ata_qc_issue_prot(qc);
  1173. }
  1174. mv_start_dma(port_mmio, hpriv, pp);
  1175. in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK;
  1176. /* until we do queuing, the queue should be empty at this point */
  1177. WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS)
  1178. >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
  1179. pp->req_idx++;
  1180. in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT;
  1181. /* and write the request in pointer to kick the EDMA to life */
  1182. writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index,
  1183. port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
  1184. return 0;
  1185. }
  1186. /**
  1187. * mv_err_intr - Handle error interrupts on the port
  1188. * @ap: ATA channel to manipulate
  1189. * @reset_allowed: bool: 0 == don't trigger from reset here
  1190. *
  1191. * In most cases, just clear the interrupt and move on. However,
  1192. * some cases require an eDMA reset, which is done right before
  1193. * the COMRESET in mv_phy_reset(). The SERR case requires a
  1194. * clear of pending errors in the SATA SERROR register. Finally,
  1195. * if the port disabled DMA, update our cached copy to match.
  1196. *
  1197. * LOCKING:
  1198. * Inherited from caller.
  1199. */
  1200. static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc)
  1201. {
  1202. void __iomem *port_mmio = mv_ap_base(ap);
  1203. u32 edma_err_cause, eh_freeze_mask, serr = 0;
  1204. struct mv_port_priv *pp = ap->private_data;
  1205. struct mv_host_priv *hpriv = ap->host->private_data;
  1206. unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN);
  1207. unsigned int action = 0, err_mask = 0;
  1208. struct ata_eh_info *ehi = &ap->link.eh_info;
  1209. ata_ehi_clear_desc(ehi);
  1210. if (!edma_enabled) {
  1211. /* just a guess: do we need to do this? should we
  1212. * expand this, and do it in all cases?
  1213. */
  1214. sata_scr_read(&ap->link, SCR_ERROR, &serr);
  1215. sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
  1216. }
  1217. edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1218. ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause);
  1219. /*
  1220. * all generations share these EDMA error cause bits
  1221. */
  1222. if (edma_err_cause & EDMA_ERR_DEV)
  1223. err_mask |= AC_ERR_DEV;
  1224. if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
  1225. EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR |
  1226. EDMA_ERR_INTRL_PAR)) {
  1227. err_mask |= AC_ERR_ATA_BUS;
  1228. action |= ATA_EH_HARDRESET;
  1229. ata_ehi_push_desc(ehi, "parity error");
  1230. }
  1231. if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) {
  1232. ata_ehi_hotplugged(ehi);
  1233. ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ?
  1234. "dev disconnect" : "dev connect");
  1235. }
  1236. if (IS_GEN_I(hpriv)) {
  1237. eh_freeze_mask = EDMA_EH_FREEZE_5;
  1238. if (edma_err_cause & EDMA_ERR_SELF_DIS_5) {
  1239. struct mv_port_priv *pp = ap->private_data;
  1240. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  1241. ata_ehi_push_desc(ehi, "EDMA self-disable");
  1242. }
  1243. } else {
  1244. eh_freeze_mask = EDMA_EH_FREEZE;
  1245. if (edma_err_cause & EDMA_ERR_SELF_DIS) {
  1246. struct mv_port_priv *pp = ap->private_data;
  1247. pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
  1248. ata_ehi_push_desc(ehi, "EDMA self-disable");
  1249. }
  1250. if (edma_err_cause & EDMA_ERR_SERR) {
  1251. sata_scr_read(&ap->link, SCR_ERROR, &serr);
  1252. sata_scr_write_flush(&ap->link, SCR_ERROR, serr);
  1253. err_mask = AC_ERR_ATA_BUS;
  1254. action |= ATA_EH_HARDRESET;
  1255. }
  1256. }
  1257. /* Clear EDMA now that SERR cleanup done */
  1258. writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1259. if (!err_mask) {
  1260. err_mask = AC_ERR_OTHER;
  1261. action |= ATA_EH_HARDRESET;
  1262. }
  1263. ehi->serror |= serr;
  1264. ehi->action |= action;
  1265. if (qc)
  1266. qc->err_mask |= err_mask;
  1267. else
  1268. ehi->err_mask |= err_mask;
  1269. if (edma_err_cause & eh_freeze_mask)
  1270. ata_port_freeze(ap);
  1271. else
  1272. ata_port_abort(ap);
  1273. }
  1274. static void mv_intr_pio(struct ata_port *ap)
  1275. {
  1276. struct ata_queued_cmd *qc;
  1277. u8 ata_status;
  1278. /* ignore spurious intr if drive still BUSY */
  1279. ata_status = readb(ap->ioaddr.status_addr);
  1280. if (unlikely(ata_status & ATA_BUSY))
  1281. return;
  1282. /* get active ATA command */
  1283. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1284. if (unlikely(!qc)) /* no active tag */
  1285. return;
  1286. if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */
  1287. return;
  1288. /* and finally, complete the ATA command */
  1289. qc->err_mask |= ac_err_mask(ata_status);
  1290. ata_qc_complete(qc);
  1291. }
  1292. static void mv_intr_edma(struct ata_port *ap)
  1293. {
  1294. void __iomem *port_mmio = mv_ap_base(ap);
  1295. struct mv_host_priv *hpriv = ap->host->private_data;
  1296. struct mv_port_priv *pp = ap->private_data;
  1297. struct ata_queued_cmd *qc;
  1298. u32 out_index, in_index;
  1299. bool work_done = false;
  1300. /* get h/w response queue pointer */
  1301. in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
  1302. >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
  1303. while (1) {
  1304. u16 status;
  1305. unsigned int tag;
  1306. /* get s/w response queue last-read pointer, and compare */
  1307. out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK;
  1308. if (in_index == out_index)
  1309. break;
  1310. /* 50xx: get active ATA command */
  1311. if (IS_GEN_I(hpriv))
  1312. tag = ap->link.active_tag;
  1313. /* Gen II/IIE: get active ATA command via tag, to enable
  1314. * support for queueing. this works transparently for
  1315. * queued and non-queued modes.
  1316. */
  1317. else if (IS_GEN_II(hpriv))
  1318. tag = (le16_to_cpu(pp->crpb[out_index].id)
  1319. >> CRPB_IOID_SHIFT_6) & 0x3f;
  1320. else /* IS_GEN_IIE */
  1321. tag = (le16_to_cpu(pp->crpb[out_index].id)
  1322. >> CRPB_IOID_SHIFT_7) & 0x3f;
  1323. qc = ata_qc_from_tag(ap, tag);
  1324. /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS
  1325. * bits (WARNING: might not necessarily be associated
  1326. * with this command), which -should- be clear
  1327. * if all is well
  1328. */
  1329. status = le16_to_cpu(pp->crpb[out_index].flags);
  1330. if (unlikely(status & 0xff)) {
  1331. mv_err_intr(ap, qc);
  1332. return;
  1333. }
  1334. /* and finally, complete the ATA command */
  1335. if (qc) {
  1336. qc->err_mask |=
  1337. ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT);
  1338. ata_qc_complete(qc);
  1339. }
  1340. /* advance software response queue pointer, to
  1341. * indicate (after the loop completes) to hardware
  1342. * that we have consumed a response queue entry.
  1343. */
  1344. work_done = true;
  1345. pp->resp_idx++;
  1346. }
  1347. if (work_done)
  1348. writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) |
  1349. (out_index << EDMA_RSP_Q_PTR_SHIFT),
  1350. port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
  1351. }
  1352. /**
  1353. * mv_host_intr - Handle all interrupts on the given host controller
  1354. * @host: host specific structure
  1355. * @relevant: port error bits relevant to this host controller
  1356. * @hc: which host controller we're to look at
  1357. *
  1358. * Read then write clear the HC interrupt status then walk each
  1359. * port connected to the HC and see if it needs servicing. Port
  1360. * success ints are reported in the HC interrupt status reg, the
  1361. * port error ints are reported in the higher level main
  1362. * interrupt status register and thus are passed in via the
  1363. * 'relevant' argument.
  1364. *
  1365. * LOCKING:
  1366. * Inherited from caller.
  1367. */
  1368. static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
  1369. {
  1370. void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
  1371. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  1372. u32 hc_irq_cause;
  1373. int port, port0;
  1374. if (hc == 0)
  1375. port0 = 0;
  1376. else
  1377. port0 = MV_PORTS_PER_HC;
  1378. /* we'll need the HC success int register in most cases */
  1379. hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
  1380. if (!hc_irq_cause)
  1381. return;
  1382. writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
  1383. VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
  1384. hc, relevant, hc_irq_cause);
  1385. for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
  1386. struct ata_port *ap = host->ports[port];
  1387. struct mv_port_priv *pp = ap->private_data;
  1388. int have_err_bits, hard_port, shift;
  1389. if ((!ap) || (ap->flags & ATA_FLAG_DISABLED))
  1390. continue;
  1391. shift = port << 1; /* (port * 2) */
  1392. if (port >= MV_PORTS_PER_HC) {
  1393. shift++; /* skip bit 8 in the HC Main IRQ reg */
  1394. }
  1395. have_err_bits = ((PORT0_ERR << shift) & relevant);
  1396. if (unlikely(have_err_bits)) {
  1397. struct ata_queued_cmd *qc;
  1398. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1399. if (qc && (qc->tf.flags & ATA_TFLAG_POLLING))
  1400. continue;
  1401. mv_err_intr(ap, qc);
  1402. continue;
  1403. }
  1404. hard_port = mv_hardport_from_port(port); /* range 0..3 */
  1405. if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
  1406. if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause)
  1407. mv_intr_edma(ap);
  1408. } else {
  1409. if ((DEV_IRQ << hard_port) & hc_irq_cause)
  1410. mv_intr_pio(ap);
  1411. }
  1412. }
  1413. VPRINTK("EXIT\n");
  1414. }
  1415. static void mv_pci_error(struct ata_host *host, void __iomem *mmio)
  1416. {
  1417. struct mv_host_priv *hpriv = host->private_data;
  1418. struct ata_port *ap;
  1419. struct ata_queued_cmd *qc;
  1420. struct ata_eh_info *ehi;
  1421. unsigned int i, err_mask, printed = 0;
  1422. u32 err_cause;
  1423. err_cause = readl(mmio + hpriv->irq_cause_ofs);
  1424. dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n",
  1425. err_cause);
  1426. DPRINTK("All regs @ PCI error\n");
  1427. mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
  1428. writelfl(0, mmio + hpriv->irq_cause_ofs);
  1429. for (i = 0; i < host->n_ports; i++) {
  1430. ap = host->ports[i];
  1431. if (!ata_link_offline(&ap->link)) {
  1432. ehi = &ap->link.eh_info;
  1433. ata_ehi_clear_desc(ehi);
  1434. if (!printed++)
  1435. ata_ehi_push_desc(ehi,
  1436. "PCI err cause 0x%08x", err_cause);
  1437. err_mask = AC_ERR_HOST_BUS;
  1438. ehi->action = ATA_EH_HARDRESET;
  1439. qc = ata_qc_from_tag(ap, ap->link.active_tag);
  1440. if (qc)
  1441. qc->err_mask |= err_mask;
  1442. else
  1443. ehi->err_mask |= err_mask;
  1444. ata_port_freeze(ap);
  1445. }
  1446. }
  1447. }
  1448. /**
  1449. * mv_interrupt - Main interrupt event handler
  1450. * @irq: unused
  1451. * @dev_instance: private data; in this case the host structure
  1452. *
  1453. * Read the read only register to determine if any host
  1454. * controllers have pending interrupts. If so, call lower level
  1455. * routine to handle. Also check for PCI errors which are only
  1456. * reported here.
  1457. *
  1458. * LOCKING:
  1459. * This routine holds the host lock while processing pending
  1460. * interrupts.
  1461. */
  1462. static irqreturn_t mv_interrupt(int irq, void *dev_instance)
  1463. {
  1464. struct ata_host *host = dev_instance;
  1465. unsigned int hc, handled = 0, n_hcs;
  1466. void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
  1467. u32 irq_stat;
  1468. irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
  1469. /* check the cases where we either have nothing pending or have read
  1470. * a bogus register value which can indicate HW removal or PCI fault
  1471. */
  1472. if (!irq_stat || (0xffffffffU == irq_stat))
  1473. return IRQ_NONE;
  1474. n_hcs = mv_get_hc_count(host->ports[0]->flags);
  1475. spin_lock(&host->lock);
  1476. if (unlikely(irq_stat & PCI_ERR)) {
  1477. mv_pci_error(host, mmio);
  1478. handled = 1;
  1479. goto out_unlock; /* skip all other HC irq handling */
  1480. }
  1481. for (hc = 0; hc < n_hcs; hc++) {
  1482. u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
  1483. if (relevant) {
  1484. mv_host_intr(host, relevant, hc);
  1485. handled = 1;
  1486. }
  1487. }
  1488. out_unlock:
  1489. spin_unlock(&host->lock);
  1490. return IRQ_RETVAL(handled);
  1491. }
  1492. static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port)
  1493. {
  1494. void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port);
  1495. unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL;
  1496. return hc_mmio + ofs;
  1497. }
  1498. static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
  1499. {
  1500. unsigned int ofs;
  1501. switch (sc_reg_in) {
  1502. case SCR_STATUS:
  1503. case SCR_ERROR:
  1504. case SCR_CONTROL:
  1505. ofs = sc_reg_in * sizeof(u32);
  1506. break;
  1507. default:
  1508. ofs = 0xffffffffU;
  1509. break;
  1510. }
  1511. return ofs;
  1512. }
  1513. static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val)
  1514. {
  1515. void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
  1516. void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
  1517. unsigned int ofs = mv5_scr_offset(sc_reg_in);
  1518. if (ofs != 0xffffffffU) {
  1519. *val = readl(addr + ofs);
  1520. return 0;
  1521. } else
  1522. return -EINVAL;
  1523. }
  1524. static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
  1525. {
  1526. void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
  1527. void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
  1528. unsigned int ofs = mv5_scr_offset(sc_reg_in);
  1529. if (ofs != 0xffffffffU) {
  1530. writelfl(val, addr + ofs);
  1531. return 0;
  1532. } else
  1533. return -EINVAL;
  1534. }
  1535. static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
  1536. {
  1537. int early_5080;
  1538. early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0);
  1539. if (!early_5080) {
  1540. u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1541. tmp |= (1 << 0);
  1542. writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1543. }
  1544. mv_reset_pci_bus(pdev, mmio);
  1545. }
  1546. static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
  1547. {
  1548. writel(0x0fcfffff, mmio + MV_FLASH_CTL);
  1549. }
  1550. static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
  1551. void __iomem *mmio)
  1552. {
  1553. void __iomem *phy_mmio = mv5_phy_base(mmio, idx);
  1554. u32 tmp;
  1555. tmp = readl(phy_mmio + MV5_PHY_MODE);
  1556. hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */
  1557. hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */
  1558. }
  1559. static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
  1560. {
  1561. u32 tmp;
  1562. writel(0, mmio + MV_GPIO_PORT_CTL);
  1563. /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */
  1564. tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1565. tmp |= ~(1 << 0);
  1566. writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
  1567. }
  1568. static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  1569. unsigned int port)
  1570. {
  1571. void __iomem *phy_mmio = mv5_phy_base(mmio, port);
  1572. const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5);
  1573. u32 tmp;
  1574. int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0);
  1575. if (fix_apm_sq) {
  1576. tmp = readl(phy_mmio + MV5_LT_MODE);
  1577. tmp |= (1 << 19);
  1578. writel(tmp, phy_mmio + MV5_LT_MODE);
  1579. tmp = readl(phy_mmio + MV5_PHY_CTL);
  1580. tmp &= ~0x3;
  1581. tmp |= 0x1;
  1582. writel(tmp, phy_mmio + MV5_PHY_CTL);
  1583. }
  1584. tmp = readl(phy_mmio + MV5_PHY_MODE);
  1585. tmp &= ~mask;
  1586. tmp |= hpriv->signal[port].pre;
  1587. tmp |= hpriv->signal[port].amps;
  1588. writel(tmp, phy_mmio + MV5_PHY_MODE);
  1589. }
  1590. #undef ZERO
  1591. #define ZERO(reg) writel(0, port_mmio + (reg))
  1592. static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio,
  1593. unsigned int port)
  1594. {
  1595. void __iomem *port_mmio = mv_port_base(mmio, port);
  1596. writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
  1597. mv_channel_reset(hpriv, mmio, port);
  1598. ZERO(0x028); /* command */
  1599. writel(0x11f, port_mmio + EDMA_CFG_OFS);
  1600. ZERO(0x004); /* timer */
  1601. ZERO(0x008); /* irq err cause */
  1602. ZERO(0x00c); /* irq err mask */
  1603. ZERO(0x010); /* rq bah */
  1604. ZERO(0x014); /* rq inp */
  1605. ZERO(0x018); /* rq outp */
  1606. ZERO(0x01c); /* respq bah */
  1607. ZERO(0x024); /* respq outp */
  1608. ZERO(0x020); /* respq inp */
  1609. ZERO(0x02c); /* test control */
  1610. writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
  1611. }
  1612. #undef ZERO
  1613. #define ZERO(reg) writel(0, hc_mmio + (reg))
  1614. static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1615. unsigned int hc)
  1616. {
  1617. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  1618. u32 tmp;
  1619. ZERO(0x00c);
  1620. ZERO(0x010);
  1621. ZERO(0x014);
  1622. ZERO(0x018);
  1623. tmp = readl(hc_mmio + 0x20);
  1624. tmp &= 0x1c1c1c1c;
  1625. tmp |= 0x03030303;
  1626. writel(tmp, hc_mmio + 0x20);
  1627. }
  1628. #undef ZERO
  1629. static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1630. unsigned int n_hc)
  1631. {
  1632. unsigned int hc, port;
  1633. for (hc = 0; hc < n_hc; hc++) {
  1634. for (port = 0; port < MV_PORTS_PER_HC; port++)
  1635. mv5_reset_hc_port(hpriv, mmio,
  1636. (hc * MV_PORTS_PER_HC) + port);
  1637. mv5_reset_one_hc(hpriv, mmio, hc);
  1638. }
  1639. return 0;
  1640. }
  1641. #undef ZERO
  1642. #define ZERO(reg) writel(0, mmio + (reg))
  1643. static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
  1644. {
  1645. struct ata_host *host = dev_get_drvdata(&pdev->dev);
  1646. struct mv_host_priv *hpriv = host->private_data;
  1647. u32 tmp;
  1648. tmp = readl(mmio + MV_PCI_MODE);
  1649. tmp &= 0xff00ffff;
  1650. writel(tmp, mmio + MV_PCI_MODE);
  1651. ZERO(MV_PCI_DISC_TIMER);
  1652. ZERO(MV_PCI_MSI_TRIGGER);
  1653. writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT);
  1654. ZERO(HC_MAIN_IRQ_MASK_OFS);
  1655. ZERO(MV_PCI_SERR_MASK);
  1656. ZERO(hpriv->irq_cause_ofs);
  1657. ZERO(hpriv->irq_mask_ofs);
  1658. ZERO(MV_PCI_ERR_LOW_ADDRESS);
  1659. ZERO(MV_PCI_ERR_HIGH_ADDRESS);
  1660. ZERO(MV_PCI_ERR_ATTRIBUTE);
  1661. ZERO(MV_PCI_ERR_COMMAND);
  1662. }
  1663. #undef ZERO
  1664. static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
  1665. {
  1666. u32 tmp;
  1667. mv5_reset_flash(hpriv, mmio);
  1668. tmp = readl(mmio + MV_GPIO_PORT_CTL);
  1669. tmp &= 0x3;
  1670. tmp |= (1 << 5) | (1 << 6);
  1671. writel(tmp, mmio + MV_GPIO_PORT_CTL);
  1672. }
  1673. /**
  1674. * mv6_reset_hc - Perform the 6xxx global soft reset
  1675. * @mmio: base address of the HBA
  1676. *
  1677. * This routine only applies to 6xxx parts.
  1678. *
  1679. * LOCKING:
  1680. * Inherited from caller.
  1681. */
  1682. static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
  1683. unsigned int n_hc)
  1684. {
  1685. void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS;
  1686. int i, rc = 0;
  1687. u32 t;
  1688. /* Following procedure defined in PCI "main command and status
  1689. * register" table.
  1690. */
  1691. t = readl(reg);
  1692. writel(t | STOP_PCI_MASTER, reg);
  1693. for (i = 0; i < 1000; i++) {
  1694. udelay(1);
  1695. t = readl(reg);
  1696. if (PCI_MASTER_EMPTY & t)
  1697. break;
  1698. }
  1699. if (!(PCI_MASTER_EMPTY & t)) {
  1700. printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
  1701. rc = 1;
  1702. goto done;
  1703. }
  1704. /* set reset */
  1705. i = 5;
  1706. do {
  1707. writel(t | GLOB_SFT_RST, reg);
  1708. t = readl(reg);
  1709. udelay(1);
  1710. } while (!(GLOB_SFT_RST & t) && (i-- > 0));
  1711. if (!(GLOB_SFT_RST & t)) {
  1712. printk(KERN_ERR DRV_NAME ": can't set global reset\n");
  1713. rc = 1;
  1714. goto done;
  1715. }
  1716. /* clear reset and *reenable the PCI master* (not mentioned in spec) */
  1717. i = 5;
  1718. do {
  1719. writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
  1720. t = readl(reg);
  1721. udelay(1);
  1722. } while ((GLOB_SFT_RST & t) && (i-- > 0));
  1723. if (GLOB_SFT_RST & t) {
  1724. printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
  1725. rc = 1;
  1726. }
  1727. done:
  1728. return rc;
  1729. }
  1730. static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
  1731. void __iomem *mmio)
  1732. {
  1733. void __iomem *port_mmio;
  1734. u32 tmp;
  1735. tmp = readl(mmio + MV_RESET_CFG);
  1736. if ((tmp & (1 << 0)) == 0) {
  1737. hpriv->signal[idx].amps = 0x7 << 8;
  1738. hpriv->signal[idx].pre = 0x1 << 5;
  1739. return;
  1740. }
  1741. port_mmio = mv_port_base(mmio, idx);
  1742. tmp = readl(port_mmio + PHY_MODE2);
  1743. hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
  1744. hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
  1745. }
  1746. static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
  1747. {
  1748. writel(0x00000060, mmio + MV_GPIO_PORT_CTL);
  1749. }
  1750. static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
  1751. unsigned int port)
  1752. {
  1753. void __iomem *port_mmio = mv_port_base(mmio, port);
  1754. u32 hp_flags = hpriv->hp_flags;
  1755. int fix_phy_mode2 =
  1756. hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
  1757. int fix_phy_mode4 =
  1758. hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
  1759. u32 m2, tmp;
  1760. if (fix_phy_mode2) {
  1761. m2 = readl(port_mmio + PHY_MODE2);
  1762. m2 &= ~(1 << 16);
  1763. m2 |= (1 << 31);
  1764. writel(m2, port_mmio + PHY_MODE2);
  1765. udelay(200);
  1766. m2 = readl(port_mmio + PHY_MODE2);
  1767. m2 &= ~((1 << 16) | (1 << 31));
  1768. writel(m2, port_mmio + PHY_MODE2);
  1769. udelay(200);
  1770. }
  1771. /* who knows what this magic does */
  1772. tmp = readl(port_mmio + PHY_MODE3);
  1773. tmp &= ~0x7F800000;
  1774. tmp |= 0x2A800000;
  1775. writel(tmp, port_mmio + PHY_MODE3);
  1776. if (fix_phy_mode4) {
  1777. u32 m4;
  1778. m4 = readl(port_mmio + PHY_MODE4);
  1779. if (hp_flags & MV_HP_ERRATA_60X1B2)
  1780. tmp = readl(port_mmio + 0x310);
  1781. m4 = (m4 & ~(1 << 1)) | (1 << 0);
  1782. writel(m4, port_mmio + PHY_MODE4);
  1783. if (hp_flags & MV_HP_ERRATA_60X1B2)
  1784. writel(tmp, port_mmio + 0x310);
  1785. }
  1786. /* Revert values of pre-emphasis and signal amps to the saved ones */
  1787. m2 = readl(port_mmio + PHY_MODE2);
  1788. m2 &= ~MV_M2_PREAMP_MASK;
  1789. m2 |= hpriv->signal[port].amps;
  1790. m2 |= hpriv->signal[port].pre;
  1791. m2 &= ~(1 << 16);
  1792. /* according to mvSata 3.6.1, some IIE values are fixed */
  1793. if (IS_GEN_IIE(hpriv)) {
  1794. m2 &= ~0xC30FF01F;
  1795. m2 |= 0x0000900F;
  1796. }
  1797. writel(m2, port_mmio + PHY_MODE2);
  1798. }
  1799. static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
  1800. unsigned int port_no)
  1801. {
  1802. void __iomem *port_mmio = mv_port_base(mmio, port_no);
  1803. writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
  1804. if (IS_GEN_II(hpriv)) {
  1805. u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
  1806. ifctl |= (1 << 7); /* enable gen2i speed */
  1807. ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */
  1808. writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
  1809. }
  1810. udelay(25); /* allow reset propagation */
  1811. /* Spec never mentions clearing the bit. Marvell's driver does
  1812. * clear the bit, however.
  1813. */
  1814. writelfl(0, port_mmio + EDMA_CMD_OFS);
  1815. hpriv->ops->phy_errata(hpriv, mmio, port_no);
  1816. if (IS_GEN_I(hpriv))
  1817. mdelay(1);
  1818. }
  1819. /**
  1820. * mv_phy_reset - Perform eDMA reset followed by COMRESET
  1821. * @ap: ATA channel to manipulate
  1822. *
  1823. * Part of this is taken from __sata_phy_reset and modified to
  1824. * not sleep since this routine gets called from interrupt level.
  1825. *
  1826. * LOCKING:
  1827. * Inherited from caller. This is coded to safe to call at
  1828. * interrupt level, i.e. it does not sleep.
  1829. */
  1830. static void mv_phy_reset(struct ata_port *ap, unsigned int *class,
  1831. unsigned long deadline)
  1832. {
  1833. struct mv_port_priv *pp = ap->private_data;
  1834. struct mv_host_priv *hpriv = ap->host->private_data;
  1835. void __iomem *port_mmio = mv_ap_base(ap);
  1836. int retry = 5;
  1837. u32 sstatus;
  1838. VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
  1839. #ifdef DEBUG
  1840. {
  1841. u32 sstatus, serror, scontrol;
  1842. mv_scr_read(ap, SCR_STATUS, &sstatus);
  1843. mv_scr_read(ap, SCR_ERROR, &serror);
  1844. mv_scr_read(ap, SCR_CONTROL, &scontrol);
  1845. DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
  1846. "SCtrl 0x%08x\n", sstatus, serror, scontrol);
  1847. }
  1848. #endif
  1849. /* Issue COMRESET via SControl */
  1850. comreset_retry:
  1851. sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x301);
  1852. msleep(1);
  1853. sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x300);
  1854. msleep(20);
  1855. do {
  1856. sata_scr_read(&ap->link, SCR_STATUS, &sstatus);
  1857. if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0))
  1858. break;
  1859. msleep(1);
  1860. } while (time_before(jiffies, deadline));
  1861. /* work around errata */
  1862. if (IS_GEN_II(hpriv) &&
  1863. (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) &&
  1864. (retry-- > 0))
  1865. goto comreset_retry;
  1866. #ifdef DEBUG
  1867. {
  1868. u32 sstatus, serror, scontrol;
  1869. mv_scr_read(ap, SCR_STATUS, &sstatus);
  1870. mv_scr_read(ap, SCR_ERROR, &serror);
  1871. mv_scr_read(ap, SCR_CONTROL, &scontrol);
  1872. DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
  1873. "SCtrl 0x%08x\n", sstatus, serror, scontrol);
  1874. }
  1875. #endif
  1876. if (ata_link_offline(&ap->link)) {
  1877. *class = ATA_DEV_NONE;
  1878. return;
  1879. }
  1880. /* even after SStatus reflects that device is ready,
  1881. * it seems to take a while for link to be fully
  1882. * established (and thus Status no longer 0x80/0x7F),
  1883. * so we poll a bit for that, here.
  1884. */
  1885. retry = 20;
  1886. while (1) {
  1887. u8 drv_stat = ata_check_status(ap);
  1888. if ((drv_stat != 0x80) && (drv_stat != 0x7f))
  1889. break;
  1890. msleep(500);
  1891. if (retry-- <= 0)
  1892. break;
  1893. if (time_after(jiffies, deadline))
  1894. break;
  1895. }
  1896. /* FIXME: if we passed the deadline, the following
  1897. * code probably produces an invalid result
  1898. */
  1899. /* finally, read device signature from TF registers */
  1900. *class = ata_dev_try_classify(ap->link.device, 1, NULL);
  1901. writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1902. WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN);
  1903. VPRINTK("EXIT\n");
  1904. }
  1905. static int mv_prereset(struct ata_link *link, unsigned long deadline)
  1906. {
  1907. struct ata_port *ap = link->ap;
  1908. struct mv_port_priv *pp = ap->private_data;
  1909. struct ata_eh_context *ehc = &link->eh_context;
  1910. int rc;
  1911. rc = mv_stop_dma(ap);
  1912. if (rc)
  1913. ehc->i.action |= ATA_EH_HARDRESET;
  1914. if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) {
  1915. pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET;
  1916. ehc->i.action |= ATA_EH_HARDRESET;
  1917. }
  1918. /* if we're about to do hardreset, nothing more to do */
  1919. if (ehc->i.action & ATA_EH_HARDRESET)
  1920. return 0;
  1921. if (ata_link_online(link))
  1922. rc = ata_wait_ready(ap, deadline);
  1923. else
  1924. rc = -ENODEV;
  1925. return rc;
  1926. }
  1927. static int mv_hardreset(struct ata_link *link, unsigned int *class,
  1928. unsigned long deadline)
  1929. {
  1930. struct ata_port *ap = link->ap;
  1931. struct mv_host_priv *hpriv = ap->host->private_data;
  1932. void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
  1933. mv_stop_dma(ap);
  1934. mv_channel_reset(hpriv, mmio, ap->port_no);
  1935. mv_phy_reset(ap, class, deadline);
  1936. return 0;
  1937. }
  1938. static void mv_postreset(struct ata_link *link, unsigned int *classes)
  1939. {
  1940. struct ata_port *ap = link->ap;
  1941. u32 serr;
  1942. /* print link status */
  1943. sata_print_link_status(link);
  1944. /* clear SError */
  1945. sata_scr_read(link, SCR_ERROR, &serr);
  1946. sata_scr_write_flush(link, SCR_ERROR, serr);
  1947. /* bail out if no device is present */
  1948. if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) {
  1949. DPRINTK("EXIT, no device\n");
  1950. return;
  1951. }
  1952. /* set up device control */
  1953. iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
  1954. }
  1955. static void mv_error_handler(struct ata_port *ap)
  1956. {
  1957. ata_do_eh(ap, mv_prereset, ata_std_softreset,
  1958. mv_hardreset, mv_postreset);
  1959. }
  1960. static void mv_post_int_cmd(struct ata_queued_cmd *qc)
  1961. {
  1962. mv_stop_dma(qc->ap);
  1963. }
  1964. static void mv_eh_freeze(struct ata_port *ap)
  1965. {
  1966. void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
  1967. unsigned int hc = (ap->port_no > 3) ? 1 : 0;
  1968. u32 tmp, mask;
  1969. unsigned int shift;
  1970. /* FIXME: handle coalescing completion events properly */
  1971. shift = ap->port_no * 2;
  1972. if (hc > 0)
  1973. shift++;
  1974. mask = 0x3 << shift;
  1975. /* disable assertion of portN err, done events */
  1976. tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
  1977. writelfl(tmp & ~mask, mmio + HC_MAIN_IRQ_MASK_OFS);
  1978. }
  1979. static void mv_eh_thaw(struct ata_port *ap)
  1980. {
  1981. void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
  1982. unsigned int hc = (ap->port_no > 3) ? 1 : 0;
  1983. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  1984. void __iomem *port_mmio = mv_ap_base(ap);
  1985. u32 tmp, mask, hc_irq_cause;
  1986. unsigned int shift, hc_port_no = ap->port_no;
  1987. /* FIXME: handle coalescing completion events properly */
  1988. shift = ap->port_no * 2;
  1989. if (hc > 0) {
  1990. shift++;
  1991. hc_port_no -= 4;
  1992. }
  1993. mask = 0x3 << shift;
  1994. /* clear EDMA errors on this port */
  1995. writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  1996. /* clear pending irq events */
  1997. hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
  1998. hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */
  1999. hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */
  2000. writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
  2001. /* enable assertion of portN err, done events */
  2002. tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS);
  2003. writelfl(tmp | mask, mmio + HC_MAIN_IRQ_MASK_OFS);
  2004. }
  2005. /**
  2006. * mv_port_init - Perform some early initialization on a single port.
  2007. * @port: libata data structure storing shadow register addresses
  2008. * @port_mmio: base address of the port
  2009. *
  2010. * Initialize shadow register mmio addresses, clear outstanding
  2011. * interrupts on the port, and unmask interrupts for the future
  2012. * start of the port.
  2013. *
  2014. * LOCKING:
  2015. * Inherited from caller.
  2016. */
  2017. static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
  2018. {
  2019. void __iomem *shd_base = port_mmio + SHD_BLK_OFS;
  2020. unsigned serr_ofs;
  2021. /* PIO related setup
  2022. */
  2023. port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
  2024. port->error_addr =
  2025. port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
  2026. port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
  2027. port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
  2028. port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
  2029. port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
  2030. port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
  2031. port->status_addr =
  2032. port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
  2033. /* special case: control/altstatus doesn't have ATA_REG_ address */
  2034. port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
  2035. /* unused: */
  2036. port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
  2037. /* Clear any currently outstanding port interrupt conditions */
  2038. serr_ofs = mv_scr_offset(SCR_ERROR);
  2039. writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
  2040. writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
  2041. /* unmask all EDMA error interrupts */
  2042. writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
  2043. VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
  2044. readl(port_mmio + EDMA_CFG_OFS),
  2045. readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
  2046. readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
  2047. }
  2048. static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
  2049. {
  2050. struct pci_dev *pdev = to_pci_dev(host->dev);
  2051. struct mv_host_priv *hpriv = host->private_data;
  2052. u32 hp_flags = hpriv->hp_flags;
  2053. switch (board_idx) {
  2054. case chip_5080:
  2055. hpriv->ops = &mv5xxx_ops;
  2056. hp_flags |= MV_HP_GEN_I;
  2057. switch (pdev->revision) {
  2058. case 0x1:
  2059. hp_flags |= MV_HP_ERRATA_50XXB0;
  2060. break;
  2061. case 0x3:
  2062. hp_flags |= MV_HP_ERRATA_50XXB2;
  2063. break;
  2064. default:
  2065. dev_printk(KERN_WARNING, &pdev->dev,
  2066. "Applying 50XXB2 workarounds to unknown rev\n");
  2067. hp_flags |= MV_HP_ERRATA_50XXB2;
  2068. break;
  2069. }
  2070. break;
  2071. case chip_504x:
  2072. case chip_508x:
  2073. hpriv->ops = &mv5xxx_ops;
  2074. hp_flags |= MV_HP_GEN_I;
  2075. switch (pdev->revision) {
  2076. case 0x0:
  2077. hp_flags |= MV_HP_ERRATA_50XXB0;
  2078. break;
  2079. case 0x3:
  2080. hp_flags |= MV_HP_ERRATA_50XXB2;
  2081. break;
  2082. default:
  2083. dev_printk(KERN_WARNING, &pdev->dev,
  2084. "Applying B2 workarounds to unknown rev\n");
  2085. hp_flags |= MV_HP_ERRATA_50XXB2;
  2086. break;
  2087. }
  2088. break;
  2089. case chip_604x:
  2090. case chip_608x:
  2091. hpriv->ops = &mv6xxx_ops;
  2092. hp_flags |= MV_HP_GEN_II;
  2093. switch (pdev->revision) {
  2094. case 0x7:
  2095. hp_flags |= MV_HP_ERRATA_60X1B2;
  2096. break;
  2097. case 0x9:
  2098. hp_flags |= MV_HP_ERRATA_60X1C0;
  2099. break;
  2100. default:
  2101. dev_printk(KERN_WARNING, &pdev->dev,
  2102. "Applying B2 workarounds to unknown rev\n");
  2103. hp_flags |= MV_HP_ERRATA_60X1B2;
  2104. break;
  2105. }
  2106. break;
  2107. case chip_7042:
  2108. hp_flags |= MV_HP_PCIE;
  2109. if (pdev->vendor == PCI_VENDOR_ID_TTI &&
  2110. (pdev->device == 0x2300 || pdev->device == 0x2310))
  2111. {
  2112. /*
  2113. * Highpoint RocketRAID PCIe 23xx series cards:
  2114. *
  2115. * Unconfigured drives are treated as "Legacy"
  2116. * by the BIOS, and it overwrites sector 8 with
  2117. * a "Lgcy" metadata block prior to Linux boot.
  2118. *
  2119. * Configured drives (RAID or JBOD) leave sector 8
  2120. * alone, but instead overwrite a high numbered
  2121. * sector for the RAID metadata. This sector can
  2122. * be determined exactly, by truncating the physical
  2123. * drive capacity to a nice even GB value.
  2124. *
  2125. * RAID metadata is at: (dev->n_sectors & ~0xfffff)
  2126. *
  2127. * Warn the user, lest they think we're just buggy.
  2128. */
  2129. printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID"
  2130. " BIOS CORRUPTS DATA on all attached drives,"
  2131. " regardless of if/how they are configured."
  2132. " BEWARE!\n");
  2133. printk(KERN_WARNING DRV_NAME ": For data safety, do not"
  2134. " use sectors 8-9 on \"Legacy\" drives,"
  2135. " and avoid the final two gigabytes on"
  2136. " all RocketRAID BIOS initialized drives.\n");
  2137. }
  2138. case chip_6042:
  2139. hpriv->ops = &mv6xxx_ops;
  2140. hp_flags |= MV_HP_GEN_IIE;
  2141. switch (pdev->revision) {
  2142. case 0x0:
  2143. hp_flags |= MV_HP_ERRATA_XX42A0;
  2144. break;
  2145. case 0x1:
  2146. hp_flags |= MV_HP_ERRATA_60X1C0;
  2147. break;
  2148. default:
  2149. dev_printk(KERN_WARNING, &pdev->dev,
  2150. "Applying 60X1C0 workarounds to unknown rev\n");
  2151. hp_flags |= MV_HP_ERRATA_60X1C0;
  2152. break;
  2153. }
  2154. break;
  2155. default:
  2156. dev_printk(KERN_ERR, &pdev->dev,
  2157. "BUG: invalid board index %u\n", board_idx);
  2158. return 1;
  2159. }
  2160. hpriv->hp_flags = hp_flags;
  2161. if (hp_flags & MV_HP_PCIE) {
  2162. hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS;
  2163. hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS;
  2164. hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS;
  2165. } else {
  2166. hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS;
  2167. hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS;
  2168. hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS;
  2169. }
  2170. return 0;
  2171. }
  2172. /**
  2173. * mv_init_host - Perform some early initialization of the host.
  2174. * @host: ATA host to initialize
  2175. * @board_idx: controller index
  2176. *
  2177. * If possible, do an early global reset of the host. Then do
  2178. * our port init and clear/unmask all/relevant host interrupts.
  2179. *
  2180. * LOCKING:
  2181. * Inherited from caller.
  2182. */
  2183. static int mv_init_host(struct ata_host *host, unsigned int board_idx)
  2184. {
  2185. int rc = 0, n_hc, port, hc;
  2186. struct pci_dev *pdev = to_pci_dev(host->dev);
  2187. void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
  2188. struct mv_host_priv *hpriv = host->private_data;
  2189. /* global interrupt mask */
  2190. writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
  2191. rc = mv_chip_id(host, board_idx);
  2192. if (rc)
  2193. goto done;
  2194. n_hc = mv_get_hc_count(host->ports[0]->flags);
  2195. for (port = 0; port < host->n_ports; port++)
  2196. hpriv->ops->read_preamp(hpriv, port, mmio);
  2197. rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
  2198. if (rc)
  2199. goto done;
  2200. hpriv->ops->reset_flash(hpriv, mmio);
  2201. hpriv->ops->reset_bus(pdev, mmio);
  2202. hpriv->ops->enable_leds(hpriv, mmio);
  2203. for (port = 0; port < host->n_ports; port++) {
  2204. if (IS_GEN_II(hpriv)) {
  2205. void __iomem *port_mmio = mv_port_base(mmio, port);
  2206. u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
  2207. ifctl |= (1 << 7); /* enable gen2i speed */
  2208. ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */
  2209. writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
  2210. }
  2211. hpriv->ops->phy_errata(hpriv, mmio, port);
  2212. }
  2213. for (port = 0; port < host->n_ports; port++) {
  2214. struct ata_port *ap = host->ports[port];
  2215. void __iomem *port_mmio = mv_port_base(mmio, port);
  2216. unsigned int offset = port_mmio - mmio;
  2217. mv_port_init(&ap->ioaddr, port_mmio);
  2218. ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
  2219. ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
  2220. }
  2221. for (hc = 0; hc < n_hc; hc++) {
  2222. void __iomem *hc_mmio = mv_hc_base(mmio, hc);
  2223. VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
  2224. "(before clear)=0x%08x\n", hc,
  2225. readl(hc_mmio + HC_CFG_OFS),
  2226. readl(hc_mmio + HC_IRQ_CAUSE_OFS));
  2227. /* Clear any currently outstanding hc interrupt conditions */
  2228. writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
  2229. }
  2230. /* Clear any currently outstanding host interrupt conditions */
  2231. writelfl(0, mmio + hpriv->irq_cause_ofs);
  2232. /* and unmask interrupt generation for host regs */
  2233. writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs);
  2234. if (IS_GEN_I(hpriv))
  2235. writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
  2236. else
  2237. writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
  2238. VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
  2239. "PCI int cause/mask=0x%08x/0x%08x\n",
  2240. readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
  2241. readl(mmio + HC_MAIN_IRQ_MASK_OFS),
  2242. readl(mmio + hpriv->irq_cause_ofs),
  2243. readl(mmio + hpriv->irq_mask_ofs));
  2244. done:
  2245. return rc;
  2246. }
  2247. /**
  2248. * mv_print_info - Dump key info to kernel log for perusal.
  2249. * @host: ATA host to print info about
  2250. *
  2251. * FIXME: complete this.
  2252. *
  2253. * LOCKING:
  2254. * Inherited from caller.
  2255. */
  2256. static void mv_print_info(struct ata_host *host)
  2257. {
  2258. struct pci_dev *pdev = to_pci_dev(host->dev);
  2259. struct mv_host_priv *hpriv = host->private_data;
  2260. u8 scc;
  2261. const char *scc_s, *gen;
  2262. /* Use this to determine the HW stepping of the chip so we know
  2263. * what errata to workaround
  2264. */
  2265. pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
  2266. if (scc == 0)
  2267. scc_s = "SCSI";
  2268. else if (scc == 0x01)
  2269. scc_s = "RAID";
  2270. else
  2271. scc_s = "?";
  2272. if (IS_GEN_I(hpriv))
  2273. gen = "I";
  2274. else if (IS_GEN_II(hpriv))
  2275. gen = "II";
  2276. else if (IS_GEN_IIE(hpriv))
  2277. gen = "IIE";
  2278. else
  2279. gen = "?";
  2280. dev_printk(KERN_INFO, &pdev->dev,
  2281. "Gen-%s %u slots %u ports %s mode IRQ via %s\n",
  2282. gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports,
  2283. scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
  2284. }
  2285. /**
  2286. * mv_init_one - handle a positive probe of a Marvell host
  2287. * @pdev: PCI device found
  2288. * @ent: PCI device ID entry for the matched host
  2289. *
  2290. * LOCKING:
  2291. * Inherited from caller.
  2292. */
  2293. static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  2294. {
  2295. static int printed_version;
  2296. unsigned int board_idx = (unsigned int)ent->driver_data;
  2297. const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL };
  2298. struct ata_host *host;
  2299. struct mv_host_priv *hpriv;
  2300. int n_ports, rc;
  2301. if (!printed_version++)
  2302. dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
  2303. /* allocate host */
  2304. n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC;
  2305. host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  2306. hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
  2307. if (!host || !hpriv)
  2308. return -ENOMEM;
  2309. host->private_data = hpriv;
  2310. /* acquire resources */
  2311. rc = pcim_enable_device(pdev);
  2312. if (rc)
  2313. return rc;
  2314. rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME);
  2315. if (rc == -EBUSY)
  2316. pcim_pin_device(pdev);
  2317. if (rc)
  2318. return rc;
  2319. host->iomap = pcim_iomap_table(pdev);
  2320. rc = pci_go_64(pdev);
  2321. if (rc)
  2322. return rc;
  2323. /* initialize adapter */
  2324. rc = mv_init_host(host, board_idx);
  2325. if (rc)
  2326. return rc;
  2327. /* Enable interrupts */
  2328. if (msi && pci_enable_msi(pdev))
  2329. pci_intx(pdev, 1);
  2330. mv_dump_pci_cfg(pdev, 0x68);
  2331. mv_print_info(host);
  2332. pci_set_master(pdev);
  2333. pci_try_set_mwi(pdev);
  2334. return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED,
  2335. IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht);
  2336. }
  2337. static int __init mv_init(void)
  2338. {
  2339. return pci_register_driver(&mv_pci_driver);
  2340. }
  2341. static void __exit mv_exit(void)
  2342. {
  2343. pci_unregister_driver(&mv_pci_driver);
  2344. }
  2345. MODULE_AUTHOR("Brett Russ");
  2346. MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
  2347. MODULE_LICENSE("GPL");
  2348. MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
  2349. MODULE_VERSION(DRV_VERSION);
  2350. module_param(msi, int, 0444);
  2351. MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)");
  2352. module_init(mv_init);
  2353. module_exit(mv_exit);