sata_mv.c 85 KB

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