1c6fd2807SJeff Garzik /* 2c6fd2807SJeff Garzik * sata_mv.c - Marvell SATA support 3c6fd2807SJeff Garzik * 440f21b11SMark Lord * Copyright 2008-2009: Marvell Corporation, all rights reserved. 5c6fd2807SJeff Garzik * Copyright 2005: EMC Corporation, all rights reserved. 6c6fd2807SJeff Garzik * Copyright 2005 Red Hat, Inc. All rights reserved. 7c6fd2807SJeff Garzik * 840f21b11SMark Lord * Originally written by Brett Russ. 940f21b11SMark Lord * Extensive overhaul and enhancement by Mark Lord <mlord@pobox.com>. 1040f21b11SMark Lord * 11c6fd2807SJeff Garzik * Please ALWAYS copy linux-ide@vger.kernel.org on emails. 12c6fd2807SJeff Garzik * 13c6fd2807SJeff Garzik * This program is free software; you can redistribute it and/or modify 14c6fd2807SJeff Garzik * it under the terms of the GNU General Public License as published by 15c6fd2807SJeff Garzik * the Free Software Foundation; version 2 of the License. 16c6fd2807SJeff Garzik * 17c6fd2807SJeff Garzik * This program is distributed in the hope that it will be useful, 18c6fd2807SJeff Garzik * but WITHOUT ANY WARRANTY; without even the implied warranty of 19c6fd2807SJeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20c6fd2807SJeff Garzik * GNU General Public License for more details. 21c6fd2807SJeff Garzik * 22c6fd2807SJeff Garzik * You should have received a copy of the GNU General Public License 23c6fd2807SJeff Garzik * along with this program; if not, write to the Free Software 24c6fd2807SJeff Garzik * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25c6fd2807SJeff Garzik * 26c6fd2807SJeff Garzik */ 27c6fd2807SJeff Garzik 284a05e209SJeff Garzik /* 2985afb934SMark Lord * sata_mv TODO list: 3085afb934SMark Lord * 3185afb934SMark Lord * --> Develop a low-power-consumption strategy, and implement it. 3285afb934SMark Lord * 332b748a0aSMark Lord * --> Add sysfs attributes for per-chip / per-HC IRQ coalescing thresholds. 3485afb934SMark Lord * 3585afb934SMark Lord * --> [Experiment, Marvell value added] Is it possible to use target 3685afb934SMark Lord * mode to cross-connect two Linux boxes with Marvell cards? If so, 3785afb934SMark Lord * creating LibATA target mode support would be very interesting. 3885afb934SMark Lord * 3985afb934SMark Lord * Target mode, for those without docs, is the ability to directly 4085afb934SMark Lord * connect two SATA ports. 414a05e209SJeff Garzik */ 424a05e209SJeff Garzik 4365ad7fefSMark Lord /* 4465ad7fefSMark Lord * 80x1-B2 errata PCI#11: 4565ad7fefSMark Lord * 4665ad7fefSMark Lord * Users of the 6041/6081 Rev.B2 chips (current is C0) 4765ad7fefSMark Lord * should be careful to insert those cards only onto PCI-X bus #0, 4865ad7fefSMark Lord * and only in device slots 0..7, not higher. The chips may not 4965ad7fefSMark Lord * work correctly otherwise (note: this is a pretty rare condition). 5065ad7fefSMark Lord */ 5165ad7fefSMark Lord 52c6fd2807SJeff Garzik #include <linux/kernel.h> 53c6fd2807SJeff Garzik #include <linux/module.h> 54c6fd2807SJeff Garzik #include <linux/pci.h> 55c6fd2807SJeff Garzik #include <linux/init.h> 56c6fd2807SJeff Garzik #include <linux/blkdev.h> 57c6fd2807SJeff Garzik #include <linux/delay.h> 58c6fd2807SJeff Garzik #include <linux/interrupt.h> 598d8b6004SAndrew Morton #include <linux/dmapool.h> 60c6fd2807SJeff Garzik #include <linux/dma-mapping.h> 61c6fd2807SJeff Garzik #include <linux/device.h> 62c77a2f4eSSaeed Bishara #include <linux/clk.h> 63b7db4f2eSAndrew Lunn #include <linux/phy/phy.h> 64f351b2d6SSaeed Bishara #include <linux/platform_device.h> 65f351b2d6SSaeed Bishara #include <linux/ata_platform.h> 6615a32632SLennert Buytenhek #include <linux/mbus.h> 67c46938ccSMark Lord #include <linux/bitops.h> 685a0e3ad6STejun Heo #include <linux/gfp.h> 6997b414e1SAndrew Lunn #include <linux/of.h> 7097b414e1SAndrew Lunn #include <linux/of_irq.h> 71c6fd2807SJeff Garzik #include <scsi/scsi_host.h> 72c6fd2807SJeff Garzik #include <scsi/scsi_cmnd.h> 736c08772eSJeff Garzik #include <scsi/scsi_device.h> 74c6fd2807SJeff Garzik #include <linux/libata.h> 75c6fd2807SJeff Garzik 76c6fd2807SJeff Garzik #define DRV_NAME "sata_mv" 77cae5a29dSMark Lord #define DRV_VERSION "1.28" 78c6fd2807SJeff Garzik 7940f21b11SMark Lord /* 8040f21b11SMark Lord * module options 8140f21b11SMark Lord */ 8240f21b11SMark Lord 8340f21b11SMark Lord #ifdef CONFIG_PCI 8413b74085SAndrew Lunn static int msi; 8540f21b11SMark Lord module_param(msi, int, S_IRUGO); 8640f21b11SMark Lord MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)"); 8740f21b11SMark Lord #endif 8840f21b11SMark Lord 892b748a0aSMark Lord static int irq_coalescing_io_count; 902b748a0aSMark Lord module_param(irq_coalescing_io_count, int, S_IRUGO); 912b748a0aSMark Lord MODULE_PARM_DESC(irq_coalescing_io_count, 922b748a0aSMark Lord "IRQ coalescing I/O count threshold (0..255)"); 932b748a0aSMark Lord 942b748a0aSMark Lord static int irq_coalescing_usecs; 952b748a0aSMark Lord module_param(irq_coalescing_usecs, int, S_IRUGO); 962b748a0aSMark Lord MODULE_PARM_DESC(irq_coalescing_usecs, 972b748a0aSMark Lord "IRQ coalescing time threshold in usecs"); 982b748a0aSMark Lord 99c6fd2807SJeff Garzik enum { 100c6fd2807SJeff Garzik /* BAR's are enumerated in terms of pci_resource_start() terms */ 101c6fd2807SJeff Garzik MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */ 102c6fd2807SJeff Garzik MV_IO_BAR = 2, /* offset 0x18: IO space */ 103c6fd2807SJeff Garzik MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */ 104c6fd2807SJeff Garzik 105c6fd2807SJeff Garzik MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */ 106c6fd2807SJeff Garzik MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */ 107c6fd2807SJeff Garzik 1082b748a0aSMark Lord /* For use with both IRQ coalescing methods ("all ports" or "per-HC" */ 1092b748a0aSMark Lord COAL_CLOCKS_PER_USEC = 150, /* for calculating COAL_TIMEs */ 1102b748a0aSMark Lord MAX_COAL_TIME_THRESHOLD = ((1 << 24) - 1), /* internal clocks count */ 1112b748a0aSMark Lord MAX_COAL_IO_COUNT = 255, /* completed I/O count */ 1122b748a0aSMark Lord 113c6fd2807SJeff Garzik MV_PCI_REG_BASE = 0, 114c6fd2807SJeff Garzik 1152b748a0aSMark Lord /* 1162b748a0aSMark Lord * Per-chip ("all ports") interrupt coalescing feature. 1172b748a0aSMark Lord * This is only for GEN_II / GEN_IIE hardware. 1182b748a0aSMark Lord * 1192b748a0aSMark Lord * Coalescing defers the interrupt until either the IO_THRESHOLD 1202b748a0aSMark Lord * (count of completed I/Os) is met, or the TIME_THRESHOLD is met. 1212b748a0aSMark Lord */ 122cae5a29dSMark Lord COAL_REG_BASE = 0x18000, 123cae5a29dSMark Lord IRQ_COAL_CAUSE = (COAL_REG_BASE + 0x08), 1242b748a0aSMark Lord ALL_PORTS_COAL_IRQ = (1 << 4), /* all ports irq event */ 1252b748a0aSMark Lord 126cae5a29dSMark Lord IRQ_COAL_IO_THRESHOLD = (COAL_REG_BASE + 0xcc), 127cae5a29dSMark Lord IRQ_COAL_TIME_THRESHOLD = (COAL_REG_BASE + 0xd0), 1282b748a0aSMark Lord 1292b748a0aSMark Lord /* 1302b748a0aSMark Lord * Registers for the (unused here) transaction coalescing feature: 1312b748a0aSMark Lord */ 132cae5a29dSMark Lord TRAN_COAL_CAUSE_LO = (COAL_REG_BASE + 0x88), 133cae5a29dSMark Lord TRAN_COAL_CAUSE_HI = (COAL_REG_BASE + 0x8c), 1342b748a0aSMark Lord 135cae5a29dSMark Lord SATAHC0_REG_BASE = 0x20000, 136cae5a29dSMark Lord FLASH_CTL = 0x1046c, 137cae5a29dSMark Lord GPIO_PORT_CTL = 0x104f0, 138cae5a29dSMark Lord RESET_CFG = 0x180d8, 139c6fd2807SJeff Garzik 140c6fd2807SJeff Garzik MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, 141c6fd2807SJeff Garzik MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, 142c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 143c6fd2807SJeff Garzik MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 144c6fd2807SJeff Garzik 145c6fd2807SJeff Garzik MV_MAX_Q_DEPTH = 32, 146c6fd2807SJeff Garzik MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, 147c6fd2807SJeff Garzik 148c6fd2807SJeff Garzik /* CRQB needs alignment on a 1KB boundary. Size == 1KB 149c6fd2807SJeff Garzik * CRPB needs alignment on a 256B boundary. Size == 256B 150c6fd2807SJeff Garzik * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B 151c6fd2807SJeff Garzik */ 152c6fd2807SJeff Garzik MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH), 153c6fd2807SJeff Garzik MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH), 154da2fa9baSMark Lord MV_MAX_SG_CT = 256, 155c6fd2807SJeff Garzik MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), 156c6fd2807SJeff Garzik 157352fab70SMark Lord /* Determine hc from 0-7 port: hc = port >> MV_PORT_HC_SHIFT */ 158c6fd2807SJeff Garzik MV_PORT_HC_SHIFT = 2, 159352fab70SMark Lord MV_PORTS_PER_HC = (1 << MV_PORT_HC_SHIFT), /* 4 */ 160352fab70SMark Lord /* Determine hc port from 0-7 port: hardport = port & MV_PORT_MASK */ 161352fab70SMark Lord MV_PORT_MASK = (MV_PORTS_PER_HC - 1), /* 3 */ 162c6fd2807SJeff Garzik 163c6fd2807SJeff Garzik /* Host Flags */ 164c6fd2807SJeff Garzik MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 1657bb3c529SSaeed Bishara 1669cbe056fSSergei Shtylyov MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_PIO_POLLING, 167ad3aef51SMark Lord 16891b1a84cSMark Lord MV_GEN_I_FLAGS = MV_COMMON_FLAGS | ATA_FLAG_NO_ATAPI, 169c6fd2807SJeff Garzik 17040f21b11SMark Lord MV_GEN_II_FLAGS = MV_COMMON_FLAGS | ATA_FLAG_NCQ | 17140f21b11SMark Lord ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA, 17291b1a84cSMark Lord 17391b1a84cSMark Lord MV_GEN_IIE_FLAGS = MV_GEN_II_FLAGS | ATA_FLAG_AN, 174ad3aef51SMark Lord 175c6fd2807SJeff Garzik CRQB_FLAG_READ = (1 << 0), 176c6fd2807SJeff Garzik CRQB_TAG_SHIFT = 1, 177c5d3e45aSJeff Garzik CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */ 178e12bef50SMark Lord CRQB_PMP_SHIFT = 12, /* CRQB Gen-II/IIE PMP shift */ 179c5d3e45aSJeff Garzik CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */ 180c6fd2807SJeff Garzik CRQB_CMD_ADDR_SHIFT = 8, 181c6fd2807SJeff Garzik CRQB_CMD_CS = (0x2 << 11), 182c6fd2807SJeff Garzik CRQB_CMD_LAST = (1 << 15), 183c6fd2807SJeff Garzik 184c6fd2807SJeff Garzik CRPB_FLAG_STATUS_SHIFT = 8, 185c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */ 186c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */ 187c6fd2807SJeff Garzik 188c6fd2807SJeff Garzik EPRD_FLAG_END_OF_TBL = (1 << 31), 189c6fd2807SJeff Garzik 190c6fd2807SJeff Garzik /* PCI interface registers */ 191c6fd2807SJeff Garzik 192cae5a29dSMark Lord MV_PCI_COMMAND = 0xc00, 193cae5a29dSMark Lord MV_PCI_COMMAND_MWRCOM = (1 << 4), /* PCI Master Write Combining */ 194cae5a29dSMark Lord MV_PCI_COMMAND_MRDTRIG = (1 << 7), /* PCI Master Read Trigger */ 195c6fd2807SJeff Garzik 196cae5a29dSMark Lord PCI_MAIN_CMD_STS = 0xd30, 197c6fd2807SJeff Garzik STOP_PCI_MASTER = (1 << 2), 198c6fd2807SJeff Garzik PCI_MASTER_EMPTY = (1 << 3), 199c6fd2807SJeff Garzik GLOB_SFT_RST = (1 << 4), 200c6fd2807SJeff Garzik 201cae5a29dSMark Lord MV_PCI_MODE = 0xd00, 2028e7decdbSMark Lord MV_PCI_MODE_MASK = 0x30, 2038e7decdbSMark Lord 204c6fd2807SJeff Garzik MV_PCI_EXP_ROM_BAR_CTL = 0xd2c, 205c6fd2807SJeff Garzik MV_PCI_DISC_TIMER = 0xd04, 206c6fd2807SJeff Garzik MV_PCI_MSI_TRIGGER = 0xc38, 207c6fd2807SJeff Garzik MV_PCI_SERR_MASK = 0xc28, 208cae5a29dSMark Lord MV_PCI_XBAR_TMOUT = 0x1d04, 209c6fd2807SJeff Garzik MV_PCI_ERR_LOW_ADDRESS = 0x1d40, 210c6fd2807SJeff Garzik MV_PCI_ERR_HIGH_ADDRESS = 0x1d44, 211c6fd2807SJeff Garzik MV_PCI_ERR_ATTRIBUTE = 0x1d48, 212c6fd2807SJeff Garzik MV_PCI_ERR_COMMAND = 0x1d50, 213c6fd2807SJeff Garzik 214cae5a29dSMark Lord PCI_IRQ_CAUSE = 0x1d58, 215cae5a29dSMark Lord PCI_IRQ_MASK = 0x1d5c, 216c6fd2807SJeff Garzik PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ 217c6fd2807SJeff Garzik 218cae5a29dSMark Lord PCIE_IRQ_CAUSE = 0x1900, 219cae5a29dSMark Lord PCIE_IRQ_MASK = 0x1910, 220646a4da5SMark Lord PCIE_UNMASK_ALL_IRQS = 0x40a, /* assorted bits */ 22102a121daSMark Lord 2227368f919SMark Lord /* Host Controller Main Interrupt Cause/Mask registers (1 per-chip) */ 223cae5a29dSMark Lord PCI_HC_MAIN_IRQ_CAUSE = 0x1d60, 224cae5a29dSMark Lord PCI_HC_MAIN_IRQ_MASK = 0x1d64, 225cae5a29dSMark Lord SOC_HC_MAIN_IRQ_CAUSE = 0x20020, 226cae5a29dSMark Lord SOC_HC_MAIN_IRQ_MASK = 0x20024, 22740f21b11SMark Lord ERR_IRQ = (1 << 0), /* shift by (2 * port #) */ 22840f21b11SMark Lord DONE_IRQ = (1 << 1), /* shift by (2 * port #) */ 229c6fd2807SJeff Garzik HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 230c6fd2807SJeff Garzik HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 2312b748a0aSMark Lord DONE_IRQ_0_3 = 0x000000aa, /* DONE_IRQ ports 0,1,2,3 */ 2322b748a0aSMark Lord DONE_IRQ_4_7 = (DONE_IRQ_0_3 << HC_SHIFT), /* 4,5,6,7 */ 233c6fd2807SJeff Garzik PCI_ERR = (1 << 18), 23440f21b11SMark Lord TRAN_COAL_LO_DONE = (1 << 19), /* transaction coalescing */ 23540f21b11SMark Lord TRAN_COAL_HI_DONE = (1 << 20), /* transaction coalescing */ 23640f21b11SMark Lord PORTS_0_3_COAL_DONE = (1 << 8), /* HC0 IRQ coalescing */ 23740f21b11SMark Lord PORTS_4_7_COAL_DONE = (1 << 17), /* HC1 IRQ coalescing */ 23840f21b11SMark Lord ALL_PORTS_COAL_DONE = (1 << 21), /* GEN_II(E) IRQ coalescing */ 239c6fd2807SJeff Garzik GPIO_INT = (1 << 22), 240c6fd2807SJeff Garzik SELF_INT = (1 << 23), 241c6fd2807SJeff Garzik TWSI_INT = (1 << 24), 242c6fd2807SJeff Garzik HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ 243fb621e2fSJeff Garzik HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */ 244f351b2d6SSaeed Bishara HC_MAIN_RSVD_SOC = (0x3fffffb << 6), /* bits 31-9, 7-6 */ 245c6fd2807SJeff Garzik 246c6fd2807SJeff Garzik /* SATAHC registers */ 247cae5a29dSMark Lord HC_CFG = 0x00, 248c6fd2807SJeff Garzik 249cae5a29dSMark Lord HC_IRQ_CAUSE = 0x14, 250352fab70SMark Lord DMA_IRQ = (1 << 0), /* shift by port # */ 251352fab70SMark Lord HC_COAL_IRQ = (1 << 4), /* IRQ coalescing */ 252c6fd2807SJeff Garzik DEV_IRQ = (1 << 8), /* shift by port # */ 253c6fd2807SJeff Garzik 2542b748a0aSMark Lord /* 2552b748a0aSMark Lord * Per-HC (Host-Controller) interrupt coalescing feature. 2562b748a0aSMark Lord * This is present on all chip generations. 2572b748a0aSMark Lord * 2582b748a0aSMark Lord * Coalescing defers the interrupt until either the IO_THRESHOLD 2592b748a0aSMark Lord * (count of completed I/Os) is met, or the TIME_THRESHOLD is met. 2602b748a0aSMark Lord */ 261cae5a29dSMark Lord HC_IRQ_COAL_IO_THRESHOLD = 0x000c, 262cae5a29dSMark Lord HC_IRQ_COAL_TIME_THRESHOLD = 0x0010, 2632b748a0aSMark Lord 264cae5a29dSMark Lord SOC_LED_CTRL = 0x2c, 265000b344fSMark Lord SOC_LED_CTRL_BLINK = (1 << 0), /* Active LED blink */ 266000b344fSMark Lord SOC_LED_CTRL_ACT_PRESENCE = (1 << 2), /* Multiplex dev presence */ 267000b344fSMark Lord /* with dev activity LED */ 268000b344fSMark Lord 269c6fd2807SJeff Garzik /* Shadow block registers */ 270cae5a29dSMark Lord SHD_BLK = 0x100, 271cae5a29dSMark Lord SHD_CTL_AST = 0x20, /* ofs from SHD_BLK */ 272c6fd2807SJeff Garzik 273c6fd2807SJeff Garzik /* SATA registers */ 274cae5a29dSMark Lord SATA_STATUS = 0x300, /* ctrl, err regs follow status */ 275cae5a29dSMark Lord SATA_ACTIVE = 0x350, 276cae5a29dSMark Lord FIS_IRQ_CAUSE = 0x364, 277cae5a29dSMark Lord FIS_IRQ_CAUSE_AN = (1 << 9), /* async notification */ 27817c5aab5SMark Lord 279cae5a29dSMark Lord LTMODE = 0x30c, /* requires read-after-write */ 28017c5aab5SMark Lord LTMODE_BIT8 = (1 << 8), /* unknown, but necessary */ 28117c5aab5SMark Lord 282cae5a29dSMark Lord PHY_MODE2 = 0x330, 283c6fd2807SJeff Garzik PHY_MODE3 = 0x310, 284cae5a29dSMark Lord 285cae5a29dSMark Lord PHY_MODE4 = 0x314, /* requires read-after-write */ 286ba069e37SMark Lord PHY_MODE4_CFG_MASK = 0x00000003, /* phy internal config field */ 287ba069e37SMark Lord PHY_MODE4_CFG_VALUE = 0x00000001, /* phy internal config field */ 288ba069e37SMark Lord PHY_MODE4_RSVD_ZEROS = 0x5de3fffa, /* Gen2e always write zeros */ 289ba069e37SMark Lord PHY_MODE4_RSVD_ONES = 0x00000005, /* Gen2e always write ones */ 290ba069e37SMark Lord 291cae5a29dSMark Lord SATA_IFCTL = 0x344, 292cae5a29dSMark Lord SATA_TESTCTL = 0x348, 293cae5a29dSMark Lord SATA_IFSTAT = 0x34c, 294cae5a29dSMark Lord VENDOR_UNIQUE_FIS = 0x35c, 29517c5aab5SMark Lord 296cae5a29dSMark Lord FISCFG = 0x360, 2978e7decdbSMark Lord FISCFG_WAIT_DEV_ERR = (1 << 8), /* wait for host on DevErr */ 2988e7decdbSMark Lord FISCFG_SINGLE_SYNC = (1 << 16), /* SYNC on DMA activation */ 29917c5aab5SMark Lord 30029b7e43cSMartin Michlmayr PHY_MODE9_GEN2 = 0x398, 30129b7e43cSMartin Michlmayr PHY_MODE9_GEN1 = 0x39c, 30229b7e43cSMartin Michlmayr PHYCFG_OFS = 0x3a0, /* only in 65n devices */ 30329b7e43cSMartin Michlmayr 304c6fd2807SJeff Garzik MV5_PHY_MODE = 0x74, 305cae5a29dSMark Lord MV5_LTMODE = 0x30, 306cae5a29dSMark Lord MV5_PHY_CTL = 0x0C, 307cae5a29dSMark Lord SATA_IFCFG = 0x050, 3089013d64eSLior Amsalem LP_PHY_CTL = 0x058, 309c6fd2807SJeff Garzik 310c6fd2807SJeff Garzik MV_M2_PREAMP_MASK = 0x7e0, 311c6fd2807SJeff Garzik 312c6fd2807SJeff Garzik /* Port registers */ 313cae5a29dSMark Lord EDMA_CFG = 0, 3140c58912eSMark Lord EDMA_CFG_Q_DEPTH = 0x1f, /* max device queue depth */ 3150c58912eSMark Lord EDMA_CFG_NCQ = (1 << 5), /* for R/W FPDMA queued */ 316c6fd2807SJeff Garzik EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */ 317c6fd2807SJeff Garzik EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */ 318c6fd2807SJeff Garzik EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */ 319e12bef50SMark Lord EDMA_CFG_EDMA_FBS = (1 << 16), /* EDMA FIS-Based Switching */ 320e12bef50SMark Lord EDMA_CFG_FBS = (1 << 26), /* FIS-Based Switching */ 321c6fd2807SJeff Garzik 322cae5a29dSMark Lord EDMA_ERR_IRQ_CAUSE = 0x8, 323cae5a29dSMark Lord EDMA_ERR_IRQ_MASK = 0xc, 3246c1153e0SJeff Garzik EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */ 3256c1153e0SJeff Garzik EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */ 3266c1153e0SJeff Garzik EDMA_ERR_DEV = (1 << 2), /* device error */ 3276c1153e0SJeff Garzik EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */ 3286c1153e0SJeff Garzik EDMA_ERR_DEV_CON = (1 << 4), /* device connected */ 3296c1153e0SJeff Garzik EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */ 330c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ 331c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ 3326c1153e0SJeff Garzik EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */ 333c5d3e45aSJeff Garzik EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ 3346c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */ 3356c1153e0SJeff Garzik EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */ 3366c1153e0SJeff Garzik EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */ 3376c1153e0SJeff Garzik EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */ 338646a4da5SMark Lord 3396c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */ 340646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_0 = (1 << 13), /* transient: CRC err */ 341646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 = (1 << 14), /* transient: FIFO err */ 342646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), /* fatal: caught SYNC */ 343646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 = (1 << 16), /* transient: FIS rx err */ 344646a4da5SMark Lord 3456c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */ 346646a4da5SMark Lord 3476c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */ 348646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_0 = (1 << 21), /* transient: CRC err */ 349646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_1 = (1 << 22), /* transient: FIFO err */ 350646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_2 = (1 << 23), /* transient: caught SYNC */ 351646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_3 = (1 << 24), /* transient: caught DMAT */ 352646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_4 = (1 << 25), /* transient: FIS collision */ 353646a4da5SMark Lord 3546c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */ 355646a4da5SMark Lord 3566c1153e0SJeff Garzik EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */ 357c5d3e45aSJeff Garzik EDMA_ERR_OVERRUN_5 = (1 << 5), 358c5d3e45aSJeff Garzik EDMA_ERR_UNDERRUN_5 = (1 << 6), 359646a4da5SMark Lord 360646a4da5SMark Lord EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 | 361646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 | 362646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 | 36385afb934SMark Lord EDMA_ERR_LNK_CTRL_TX, 364646a4da5SMark Lord 365bdd4dddeSJeff Garzik EDMA_EH_FREEZE = EDMA_ERR_D_PAR | 366bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 367bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 368bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 369bdd4dddeSJeff Garzik EDMA_ERR_SERR | 370bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS | 3716c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 372bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 373bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 374bdd4dddeSJeff Garzik EDMA_ERR_IORDY | 375bdd4dddeSJeff Garzik EDMA_ERR_LNK_CTRL_RX_2 | 376c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_RX | 377c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_TX | 378bdd4dddeSJeff Garzik EDMA_ERR_TRANS_PROTO, 379e12bef50SMark Lord 380bdd4dddeSJeff Garzik EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR | 381bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 382bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 383bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 384bdd4dddeSJeff Garzik EDMA_ERR_OVERRUN_5 | 385bdd4dddeSJeff Garzik EDMA_ERR_UNDERRUN_5 | 386bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS_5 | 3876c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 388bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 389bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 390bdd4dddeSJeff Garzik EDMA_ERR_IORDY, 391c6fd2807SJeff Garzik 392cae5a29dSMark Lord EDMA_REQ_Q_BASE_HI = 0x10, 393cae5a29dSMark Lord EDMA_REQ_Q_IN_PTR = 0x14, /* also contains BASE_LO */ 394c6fd2807SJeff Garzik 395cae5a29dSMark Lord EDMA_REQ_Q_OUT_PTR = 0x18, 396c6fd2807SJeff Garzik EDMA_REQ_Q_PTR_SHIFT = 5, 397c6fd2807SJeff Garzik 398cae5a29dSMark Lord EDMA_RSP_Q_BASE_HI = 0x1c, 399cae5a29dSMark Lord EDMA_RSP_Q_IN_PTR = 0x20, 400cae5a29dSMark Lord EDMA_RSP_Q_OUT_PTR = 0x24, /* also contains BASE_LO */ 401c6fd2807SJeff Garzik EDMA_RSP_Q_PTR_SHIFT = 3, 402c6fd2807SJeff Garzik 403cae5a29dSMark Lord EDMA_CMD = 0x28, /* EDMA command register */ 4040ea9e179SJeff Garzik EDMA_EN = (1 << 0), /* enable EDMA */ 4050ea9e179SJeff Garzik EDMA_DS = (1 << 1), /* disable EDMA; self-negated */ 4068e7decdbSMark Lord EDMA_RESET = (1 << 2), /* reset eng/trans/link/phy */ 407c6fd2807SJeff Garzik 408cae5a29dSMark Lord EDMA_STATUS = 0x30, /* EDMA engine status */ 4098e7decdbSMark Lord EDMA_STATUS_CACHE_EMPTY = (1 << 6), /* GenIIe command cache empty */ 4108e7decdbSMark Lord EDMA_STATUS_IDLE = (1 << 7), /* GenIIe EDMA enabled/idle */ 4118e7decdbSMark Lord 412cae5a29dSMark Lord EDMA_IORDY_TMOUT = 0x34, 413cae5a29dSMark Lord EDMA_ARB_CFG = 0x38, 4148e7decdbSMark Lord 415cae5a29dSMark Lord EDMA_HALTCOND = 0x60, /* GenIIe halt conditions */ 416cae5a29dSMark Lord EDMA_UNKNOWN_RSVD = 0x6C, /* GenIIe unknown/reserved */ 417da14265eSMark Lord 418cae5a29dSMark Lord BMDMA_CMD = 0x224, /* bmdma command register */ 419cae5a29dSMark Lord BMDMA_STATUS = 0x228, /* bmdma status register */ 420cae5a29dSMark Lord BMDMA_PRD_LOW = 0x22c, /* bmdma PRD addr 31:0 */ 421cae5a29dSMark Lord BMDMA_PRD_HIGH = 0x230, /* bmdma PRD addr 63:32 */ 422da14265eSMark Lord 423c6fd2807SJeff Garzik /* Host private flags (hp_flags) */ 424c6fd2807SJeff Garzik MV_HP_FLAG_MSI = (1 << 0), 425c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB0 = (1 << 1), 426c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB2 = (1 << 2), 427c6fd2807SJeff Garzik MV_HP_ERRATA_60X1B2 = (1 << 3), 428c6fd2807SJeff Garzik MV_HP_ERRATA_60X1C0 = (1 << 4), 4290ea9e179SJeff Garzik MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */ 4300ea9e179SJeff Garzik MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */ 4310ea9e179SJeff Garzik MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */ 43202a121daSMark Lord MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */ 433616d4a98SMark Lord MV_HP_CUT_THROUGH = (1 << 10), /* can use EDMA cut-through */ 4341f398472SMark Lord MV_HP_FLAG_SOC = (1 << 11), /* SystemOnChip, no PCI */ 435000b344fSMark Lord MV_HP_QUIRK_LED_BLINK_EN = (1 << 12), /* is led blinking enabled? */ 4369013d64eSLior Amsalem MV_HP_FIX_LP_PHY_CTL = (1 << 13), /* fix speed in LP_PHY_CTL ? */ 437c6fd2807SJeff Garzik 438c6fd2807SJeff Garzik /* Port private flags (pp_flags) */ 4390ea9e179SJeff Garzik MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ 44072109168SMark Lord MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */ 44100f42eabSMark Lord MV_PP_FLAG_FBS_EN = (1 << 2), /* is EDMA set up for FBS? */ 44229d187bbSMark Lord MV_PP_FLAG_DELAYED_EH = (1 << 3), /* delayed dev err handling */ 443d16ab3f6SMark Lord MV_PP_FLAG_FAKE_ATA_BUSY = (1 << 4), /* ignore initial ATA_DRDY */ 444c6fd2807SJeff Garzik }; 445c6fd2807SJeff Garzik 446ee9ccdf7SJeff Garzik #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) 447ee9ccdf7SJeff Garzik #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II) 448c6fd2807SJeff Garzik #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 4498e7decdbSMark Lord #define IS_PCIE(hpriv) ((hpriv)->hp_flags & MV_HP_PCIE) 4501f398472SMark Lord #define IS_SOC(hpriv) ((hpriv)->hp_flags & MV_HP_FLAG_SOC) 451c6fd2807SJeff Garzik 45215a32632SLennert Buytenhek #define WINDOW_CTRL(i) (0x20030 + ((i) << 4)) 45315a32632SLennert Buytenhek #define WINDOW_BASE(i) (0x20034 + ((i) << 4)) 45415a32632SLennert Buytenhek 455c6fd2807SJeff Garzik enum { 456baf14aa1SJeff Garzik /* DMA boundary 0xffff is required by the s/g splitting 457baf14aa1SJeff Garzik * we need on /length/ in mv_fill-sg(). 458baf14aa1SJeff Garzik */ 459baf14aa1SJeff Garzik MV_DMA_BOUNDARY = 0xffffU, 460c6fd2807SJeff Garzik 4610ea9e179SJeff Garzik /* mask of register bits containing lower 32 bits 4620ea9e179SJeff Garzik * of EDMA request queue DMA address 4630ea9e179SJeff Garzik */ 464c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 465c6fd2807SJeff Garzik 4660ea9e179SJeff Garzik /* ditto, for response queue */ 467c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, 468c6fd2807SJeff Garzik }; 469c6fd2807SJeff Garzik 470c6fd2807SJeff Garzik enum chip_type { 471c6fd2807SJeff Garzik chip_504x, 472c6fd2807SJeff Garzik chip_508x, 473c6fd2807SJeff Garzik chip_5080, 474c6fd2807SJeff Garzik chip_604x, 475c6fd2807SJeff Garzik chip_608x, 476c6fd2807SJeff Garzik chip_6042, 477c6fd2807SJeff Garzik chip_7042, 478f351b2d6SSaeed Bishara chip_soc, 479c6fd2807SJeff Garzik }; 480c6fd2807SJeff Garzik 481c6fd2807SJeff Garzik /* Command ReQuest Block: 32B */ 482c6fd2807SJeff Garzik struct mv_crqb { 483c6fd2807SJeff Garzik __le32 sg_addr; 484c6fd2807SJeff Garzik __le32 sg_addr_hi; 485c6fd2807SJeff Garzik __le16 ctrl_flags; 486c6fd2807SJeff Garzik __le16 ata_cmd[11]; 487c6fd2807SJeff Garzik }; 488c6fd2807SJeff Garzik 489c6fd2807SJeff Garzik struct mv_crqb_iie { 490c6fd2807SJeff Garzik __le32 addr; 491c6fd2807SJeff Garzik __le32 addr_hi; 492c6fd2807SJeff Garzik __le32 flags; 493c6fd2807SJeff Garzik __le32 len; 494c6fd2807SJeff Garzik __le32 ata_cmd[4]; 495c6fd2807SJeff Garzik }; 496c6fd2807SJeff Garzik 497c6fd2807SJeff Garzik /* Command ResPonse Block: 8B */ 498c6fd2807SJeff Garzik struct mv_crpb { 499c6fd2807SJeff Garzik __le16 id; 500c6fd2807SJeff Garzik __le16 flags; 501c6fd2807SJeff Garzik __le32 tmstmp; 502c6fd2807SJeff Garzik }; 503c6fd2807SJeff Garzik 504c6fd2807SJeff Garzik /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */ 505c6fd2807SJeff Garzik struct mv_sg { 506c6fd2807SJeff Garzik __le32 addr; 507c6fd2807SJeff Garzik __le32 flags_size; 508c6fd2807SJeff Garzik __le32 addr_hi; 509c6fd2807SJeff Garzik __le32 reserved; 510c6fd2807SJeff Garzik }; 511c6fd2807SJeff Garzik 51208da1759SMark Lord /* 51308da1759SMark Lord * We keep a local cache of a few frequently accessed port 51408da1759SMark Lord * registers here, to avoid having to read them (very slow) 51508da1759SMark Lord * when switching between EDMA and non-EDMA modes. 51608da1759SMark Lord */ 51708da1759SMark Lord struct mv_cached_regs { 51808da1759SMark Lord u32 fiscfg; 51908da1759SMark Lord u32 ltmode; 52008da1759SMark Lord u32 haltcond; 521c01e8a23SMark Lord u32 unknown_rsvd; 52208da1759SMark Lord }; 52308da1759SMark Lord 524c6fd2807SJeff Garzik struct mv_port_priv { 525c6fd2807SJeff Garzik struct mv_crqb *crqb; 526c6fd2807SJeff Garzik dma_addr_t crqb_dma; 527c6fd2807SJeff Garzik struct mv_crpb *crpb; 528c6fd2807SJeff Garzik dma_addr_t crpb_dma; 529eb73d558SMark Lord struct mv_sg *sg_tbl[MV_MAX_Q_DEPTH]; 530eb73d558SMark Lord dma_addr_t sg_tbl_dma[MV_MAX_Q_DEPTH]; 531bdd4dddeSJeff Garzik 532bdd4dddeSJeff Garzik unsigned int req_idx; 533bdd4dddeSJeff Garzik unsigned int resp_idx; 534bdd4dddeSJeff Garzik 535c6fd2807SJeff Garzik u32 pp_flags; 53608da1759SMark Lord struct mv_cached_regs cached; 53729d187bbSMark Lord unsigned int delayed_eh_pmp_map; 538c6fd2807SJeff Garzik }; 539c6fd2807SJeff Garzik 540c6fd2807SJeff Garzik struct mv_port_signal { 541c6fd2807SJeff Garzik u32 amps; 542c6fd2807SJeff Garzik u32 pre; 543c6fd2807SJeff Garzik }; 544c6fd2807SJeff Garzik 54502a121daSMark Lord struct mv_host_priv { 54602a121daSMark Lord u32 hp_flags; 5471bfeff03SSaeed Bishara unsigned int board_idx; 54896e2c487SMark Lord u32 main_irq_mask; 54902a121daSMark Lord struct mv_port_signal signal[8]; 55002a121daSMark Lord const struct mv_hw_ops *ops; 551f351b2d6SSaeed Bishara int n_ports; 552f351b2d6SSaeed Bishara void __iomem *base; 5537368f919SMark Lord void __iomem *main_irq_cause_addr; 5547368f919SMark Lord void __iomem *main_irq_mask_addr; 555cae5a29dSMark Lord u32 irq_cause_offset; 556cae5a29dSMark Lord u32 irq_mask_offset; 55702a121daSMark Lord u32 unmask_all_irqs; 558c77a2f4eSSaeed Bishara 559e0067f0bSEzequiel Garcia /* 560e0067f0bSEzequiel Garcia * Needed on some devices that require their clocks to be enabled. 561e0067f0bSEzequiel Garcia * These are optional: if the platform device does not have any 562e0067f0bSEzequiel Garcia * clocks, they won't be used. Also, if the underlying hardware 563e0067f0bSEzequiel Garcia * does not support the common clock framework (CONFIG_HAVE_CLK=n), 564e0067f0bSEzequiel Garcia * all the clock operations become no-ops (see clk.h). 565e0067f0bSEzequiel Garcia */ 566c77a2f4eSSaeed Bishara struct clk *clk; 567eee98990SAndrew Lunn struct clk **port_clks; 568da2fa9baSMark Lord /* 569b7db4f2eSAndrew Lunn * Some devices have a SATA PHY which can be enabled/disabled 570b7db4f2eSAndrew Lunn * in order to save power. These are optional: if the platform 571b7db4f2eSAndrew Lunn * devices does not have any phy, they won't be used. 572b7db4f2eSAndrew Lunn */ 573b7db4f2eSAndrew Lunn struct phy **port_phys; 574b7db4f2eSAndrew Lunn /* 575da2fa9baSMark Lord * These consistent DMA memory pools give us guaranteed 576da2fa9baSMark Lord * alignment for hardware-accessed data structures, 577da2fa9baSMark Lord * and less memory waste in accomplishing the alignment. 578da2fa9baSMark Lord */ 579da2fa9baSMark Lord struct dma_pool *crqb_pool; 580da2fa9baSMark Lord struct dma_pool *crpb_pool; 581da2fa9baSMark Lord struct dma_pool *sg_tbl_pool; 58202a121daSMark Lord }; 58302a121daSMark Lord 584c6fd2807SJeff Garzik struct mv_hw_ops { 585c6fd2807SJeff Garzik void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, 586c6fd2807SJeff Garzik unsigned int port); 587c6fd2807SJeff Garzik void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio); 588c6fd2807SJeff Garzik void (*read_preamp)(struct mv_host_priv *hpriv, int idx, 589c6fd2807SJeff Garzik void __iomem *mmio); 590c6fd2807SJeff Garzik int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio, 591c6fd2807SJeff Garzik unsigned int n_hc); 592c6fd2807SJeff Garzik void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio); 5937bb3c529SSaeed Bishara void (*reset_bus)(struct ata_host *host, void __iomem *mmio); 594c6fd2807SJeff Garzik }; 595c6fd2807SJeff Garzik 59682ef04fbSTejun Heo static int mv_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val); 59782ef04fbSTejun Heo static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val); 59882ef04fbSTejun Heo static int mv5_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val); 59982ef04fbSTejun Heo static int mv5_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val); 600c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap); 601c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap); 6023e4a1391SMark Lord static int mv_qc_defer(struct ata_queued_cmd *qc); 603c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc); 604c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 605c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 606a1efdabaSTejun Heo static int mv_hardreset(struct ata_link *link, unsigned int *class, 607a1efdabaSTejun Heo unsigned long deadline); 608bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap); 609bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap); 610f273827eSMark Lord static void mv6_dev_config(struct ata_device *dev); 611c6fd2807SJeff Garzik 612c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 613c6fd2807SJeff Garzik unsigned int port); 614c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 615c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 616c6fd2807SJeff Garzik void __iomem *mmio); 617c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 618c6fd2807SJeff Garzik unsigned int n_hc); 619c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 6207bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio); 621c6fd2807SJeff Garzik 622c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 623c6fd2807SJeff Garzik unsigned int port); 624c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 625c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 626c6fd2807SJeff Garzik void __iomem *mmio); 627c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 628c6fd2807SJeff Garzik unsigned int n_hc); 629c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 630f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 631f351b2d6SSaeed Bishara void __iomem *mmio); 632f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 633f351b2d6SSaeed Bishara void __iomem *mmio); 634f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 635f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc); 636f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 637f351b2d6SSaeed Bishara void __iomem *mmio); 638f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio); 63929b7e43cSMartin Michlmayr static void mv_soc_65n_phy_errata(struct mv_host_priv *hpriv, 64029b7e43cSMartin Michlmayr void __iomem *mmio, unsigned int port); 6417bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio); 642e12bef50SMark Lord static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio, 643c6fd2807SJeff Garzik unsigned int port_no); 644e12bef50SMark Lord static int mv_stop_edma(struct ata_port *ap); 645b562468cSMark Lord static int mv_stop_edma_engine(void __iomem *port_mmio); 64600b81235SMark Lord static void mv_edma_cfg(struct ata_port *ap, int want_ncq, int want_edma); 647c6fd2807SJeff Garzik 648e49856d8SMark Lord static void mv_pmp_select(struct ata_port *ap, int pmp); 649e49856d8SMark Lord static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class, 650e49856d8SMark Lord unsigned long deadline); 651e49856d8SMark Lord static int mv_softreset(struct ata_link *link, unsigned int *class, 652e49856d8SMark Lord unsigned long deadline); 65329d187bbSMark Lord static void mv_pmp_error_handler(struct ata_port *ap); 6544c299ca3SMark Lord static void mv_process_crpb_entries(struct ata_port *ap, 6554c299ca3SMark Lord struct mv_port_priv *pp); 656c6fd2807SJeff Garzik 657da14265eSMark Lord static void mv_sff_irq_clear(struct ata_port *ap); 658da14265eSMark Lord static int mv_check_atapi_dma(struct ata_queued_cmd *qc); 659da14265eSMark Lord static void mv_bmdma_setup(struct ata_queued_cmd *qc); 660da14265eSMark Lord static void mv_bmdma_start(struct ata_queued_cmd *qc); 661da14265eSMark Lord static void mv_bmdma_stop(struct ata_queued_cmd *qc); 662da14265eSMark Lord static u8 mv_bmdma_status(struct ata_port *ap); 663d16ab3f6SMark Lord static u8 mv_sff_check_status(struct ata_port *ap); 664da14265eSMark Lord 665eb73d558SMark Lord /* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below 666eb73d558SMark Lord * because we have to allow room for worst case splitting of 667eb73d558SMark Lord * PRDs for 64K boundaries in mv_fill_sg(). 668eb73d558SMark Lord */ 66913b74085SAndrew Lunn #ifdef CONFIG_PCI 670c5d3e45aSJeff Garzik static struct scsi_host_template mv5_sht = { 67168d1d07bSTejun Heo ATA_BASE_SHT(DRV_NAME), 672baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 673c5d3e45aSJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 674c5d3e45aSJeff Garzik }; 67513b74085SAndrew Lunn #endif 676c5d3e45aSJeff Garzik static struct scsi_host_template mv6_sht = { 67768d1d07bSTejun Heo ATA_NCQ_SHT(DRV_NAME), 678138bfdd0SMark Lord .can_queue = MV_MAX_Q_DEPTH - 1, 679baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 680c6fd2807SJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 681c6fd2807SJeff Garzik }; 682c6fd2807SJeff Garzik 683029cfd6bSTejun Heo static struct ata_port_operations mv5_ops = { 684029cfd6bSTejun Heo .inherits = &ata_sff_port_ops, 685c6fd2807SJeff Garzik 686c96f1732SAlan Cox .lost_interrupt = ATA_OP_NULL, 687c96f1732SAlan Cox 6883e4a1391SMark Lord .qc_defer = mv_qc_defer, 689c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 690c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 691c6fd2807SJeff Garzik 692bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 693bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 694a1efdabaSTejun Heo .hardreset = mv_hardreset, 695bdd4dddeSJeff Garzik 696c6fd2807SJeff Garzik .scr_read = mv5_scr_read, 697c6fd2807SJeff Garzik .scr_write = mv5_scr_write, 698c6fd2807SJeff Garzik 699c6fd2807SJeff Garzik .port_start = mv_port_start, 700c6fd2807SJeff Garzik .port_stop = mv_port_stop, 701c6fd2807SJeff Garzik }; 702c6fd2807SJeff Garzik 703029cfd6bSTejun Heo static struct ata_port_operations mv6_ops = { 7048930ff25STejun Heo .inherits = &ata_bmdma_port_ops, 705c6fd2807SJeff Garzik 7068930ff25STejun Heo .lost_interrupt = ATA_OP_NULL, 7078930ff25STejun Heo 7088930ff25STejun Heo .qc_defer = mv_qc_defer, 7098930ff25STejun Heo .qc_prep = mv_qc_prep, 7108930ff25STejun Heo .qc_issue = mv_qc_issue, 7118930ff25STejun Heo 7128930ff25STejun Heo .dev_config = mv6_dev_config, 7138930ff25STejun Heo 7148930ff25STejun Heo .freeze = mv_eh_freeze, 7158930ff25STejun Heo .thaw = mv_eh_thaw, 7168930ff25STejun Heo .hardreset = mv_hardreset, 7178930ff25STejun Heo .softreset = mv_softreset, 718e49856d8SMark Lord .pmp_hardreset = mv_pmp_hardreset, 719e49856d8SMark Lord .pmp_softreset = mv_softreset, 72029d187bbSMark Lord .error_handler = mv_pmp_error_handler, 721da14265eSMark Lord 7228930ff25STejun Heo .scr_read = mv_scr_read, 7238930ff25STejun Heo .scr_write = mv_scr_write, 7248930ff25STejun Heo 725d16ab3f6SMark Lord .sff_check_status = mv_sff_check_status, 726da14265eSMark Lord .sff_irq_clear = mv_sff_irq_clear, 727da14265eSMark Lord .check_atapi_dma = mv_check_atapi_dma, 728da14265eSMark Lord .bmdma_setup = mv_bmdma_setup, 729da14265eSMark Lord .bmdma_start = mv_bmdma_start, 730da14265eSMark Lord .bmdma_stop = mv_bmdma_stop, 731da14265eSMark Lord .bmdma_status = mv_bmdma_status, 7328930ff25STejun Heo 7338930ff25STejun Heo .port_start = mv_port_start, 7348930ff25STejun Heo .port_stop = mv_port_stop, 735c6fd2807SJeff Garzik }; 736c6fd2807SJeff Garzik 737029cfd6bSTejun Heo static struct ata_port_operations mv_iie_ops = { 738029cfd6bSTejun Heo .inherits = &mv6_ops, 739029cfd6bSTejun Heo .dev_config = ATA_OP_NULL, 740c6fd2807SJeff Garzik .qc_prep = mv_qc_prep_iie, 741c6fd2807SJeff Garzik }; 742c6fd2807SJeff Garzik 743c6fd2807SJeff Garzik static const struct ata_port_info mv_port_info[] = { 744c6fd2807SJeff Garzik { /* chip_504x */ 74591b1a84cSMark Lord .flags = MV_GEN_I_FLAGS, 746c361acbcSMark Lord .pio_mask = ATA_PIO4, 747bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 748c6fd2807SJeff Garzik .port_ops = &mv5_ops, 749c6fd2807SJeff Garzik }, 750c6fd2807SJeff Garzik { /* chip_508x */ 75191b1a84cSMark Lord .flags = MV_GEN_I_FLAGS | MV_FLAG_DUAL_HC, 752c361acbcSMark Lord .pio_mask = ATA_PIO4, 753bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 754c6fd2807SJeff Garzik .port_ops = &mv5_ops, 755c6fd2807SJeff Garzik }, 756c6fd2807SJeff Garzik { /* chip_5080 */ 75791b1a84cSMark Lord .flags = MV_GEN_I_FLAGS | MV_FLAG_DUAL_HC, 758c361acbcSMark Lord .pio_mask = ATA_PIO4, 759bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 760c6fd2807SJeff Garzik .port_ops = &mv5_ops, 761c6fd2807SJeff Garzik }, 762c6fd2807SJeff Garzik { /* chip_604x */ 76391b1a84cSMark Lord .flags = MV_GEN_II_FLAGS, 764c361acbcSMark Lord .pio_mask = ATA_PIO4, 765bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 766c6fd2807SJeff Garzik .port_ops = &mv6_ops, 767c6fd2807SJeff Garzik }, 768c6fd2807SJeff Garzik { /* chip_608x */ 76991b1a84cSMark Lord .flags = MV_GEN_II_FLAGS | MV_FLAG_DUAL_HC, 770c361acbcSMark Lord .pio_mask = ATA_PIO4, 771bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 772c6fd2807SJeff Garzik .port_ops = &mv6_ops, 773c6fd2807SJeff Garzik }, 774c6fd2807SJeff Garzik { /* chip_6042 */ 77591b1a84cSMark Lord .flags = MV_GEN_IIE_FLAGS, 776c361acbcSMark Lord .pio_mask = ATA_PIO4, 777bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 778c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 779c6fd2807SJeff Garzik }, 780c6fd2807SJeff Garzik { /* chip_7042 */ 78191b1a84cSMark Lord .flags = MV_GEN_IIE_FLAGS, 782c361acbcSMark Lord .pio_mask = ATA_PIO4, 783bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 784c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 785c6fd2807SJeff Garzik }, 786f351b2d6SSaeed Bishara { /* chip_soc */ 78791b1a84cSMark Lord .flags = MV_GEN_IIE_FLAGS, 788c361acbcSMark Lord .pio_mask = ATA_PIO4, 789f351b2d6SSaeed Bishara .udma_mask = ATA_UDMA6, 790f351b2d6SSaeed Bishara .port_ops = &mv_iie_ops, 791f351b2d6SSaeed Bishara }, 792c6fd2807SJeff Garzik }; 793c6fd2807SJeff Garzik 794c6fd2807SJeff Garzik static const struct pci_device_id mv_pci_tbl[] = { 7952d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5040), chip_504x }, 7962d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 7972d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 7982d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 79946c5784cSMark Lord /* RocketRAID 1720/174x have different identifiers */ 80046c5784cSMark Lord { PCI_VDEVICE(TTI, 0x1720), chip_6042 }, 8014462254aSMark Lord { PCI_VDEVICE(TTI, 0x1740), chip_6042 }, 8024462254aSMark Lord { PCI_VDEVICE(TTI, 0x1742), chip_6042 }, 803c6fd2807SJeff Garzik 8042d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6040), chip_604x }, 8052d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6041), chip_604x }, 8062d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 }, 8072d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6080), chip_608x }, 8082d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6081), chip_608x }, 809c6fd2807SJeff Garzik 8102d2744fcSJeff Garzik { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 8112d2744fcSJeff Garzik 812d9f9c6bcSFlorian Attenberger /* Adaptec 1430SA */ 813d9f9c6bcSFlorian Attenberger { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 }, 814d9f9c6bcSFlorian Attenberger 81502a121daSMark Lord /* Marvell 7042 support */ 8166a3d586dSMorrison, Tom { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 }, 8176a3d586dSMorrison, Tom 81802a121daSMark Lord /* Highpoint RocketRAID PCIe series */ 81902a121daSMark Lord { PCI_VDEVICE(TTI, 0x2300), chip_7042 }, 82002a121daSMark Lord { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 82102a121daSMark Lord 822c6fd2807SJeff Garzik { } /* terminate list */ 823c6fd2807SJeff Garzik }; 824c6fd2807SJeff Garzik 825c6fd2807SJeff Garzik static const struct mv_hw_ops mv5xxx_ops = { 826c6fd2807SJeff Garzik .phy_errata = mv5_phy_errata, 827c6fd2807SJeff Garzik .enable_leds = mv5_enable_leds, 828c6fd2807SJeff Garzik .read_preamp = mv5_read_preamp, 829c6fd2807SJeff Garzik .reset_hc = mv5_reset_hc, 830c6fd2807SJeff Garzik .reset_flash = mv5_reset_flash, 831c6fd2807SJeff Garzik .reset_bus = mv5_reset_bus, 832c6fd2807SJeff Garzik }; 833c6fd2807SJeff Garzik 834c6fd2807SJeff Garzik static const struct mv_hw_ops mv6xxx_ops = { 835c6fd2807SJeff Garzik .phy_errata = mv6_phy_errata, 836c6fd2807SJeff Garzik .enable_leds = mv6_enable_leds, 837c6fd2807SJeff Garzik .read_preamp = mv6_read_preamp, 838c6fd2807SJeff Garzik .reset_hc = mv6_reset_hc, 839c6fd2807SJeff Garzik .reset_flash = mv6_reset_flash, 840c6fd2807SJeff Garzik .reset_bus = mv_reset_pci_bus, 841c6fd2807SJeff Garzik }; 842c6fd2807SJeff Garzik 843f351b2d6SSaeed Bishara static const struct mv_hw_ops mv_soc_ops = { 844f351b2d6SSaeed Bishara .phy_errata = mv6_phy_errata, 845f351b2d6SSaeed Bishara .enable_leds = mv_soc_enable_leds, 846f351b2d6SSaeed Bishara .read_preamp = mv_soc_read_preamp, 847f351b2d6SSaeed Bishara .reset_hc = mv_soc_reset_hc, 848f351b2d6SSaeed Bishara .reset_flash = mv_soc_reset_flash, 849f351b2d6SSaeed Bishara .reset_bus = mv_soc_reset_bus, 850f351b2d6SSaeed Bishara }; 851f351b2d6SSaeed Bishara 85229b7e43cSMartin Michlmayr static const struct mv_hw_ops mv_soc_65n_ops = { 85329b7e43cSMartin Michlmayr .phy_errata = mv_soc_65n_phy_errata, 85429b7e43cSMartin Michlmayr .enable_leds = mv_soc_enable_leds, 85529b7e43cSMartin Michlmayr .reset_hc = mv_soc_reset_hc, 85629b7e43cSMartin Michlmayr .reset_flash = mv_soc_reset_flash, 85729b7e43cSMartin Michlmayr .reset_bus = mv_soc_reset_bus, 85829b7e43cSMartin Michlmayr }; 85929b7e43cSMartin Michlmayr 860c6fd2807SJeff Garzik /* 861c6fd2807SJeff Garzik * Functions 862c6fd2807SJeff Garzik */ 863c6fd2807SJeff Garzik 864c6fd2807SJeff Garzik static inline void writelfl(unsigned long data, void __iomem *addr) 865c6fd2807SJeff Garzik { 866c6fd2807SJeff Garzik writel(data, addr); 867c6fd2807SJeff Garzik (void) readl(addr); /* flush to avoid PCI posted write */ 868c6fd2807SJeff Garzik } 869c6fd2807SJeff Garzik 870c6fd2807SJeff Garzik static inline unsigned int mv_hc_from_port(unsigned int port) 871c6fd2807SJeff Garzik { 872c6fd2807SJeff Garzik return port >> MV_PORT_HC_SHIFT; 873c6fd2807SJeff Garzik } 874c6fd2807SJeff Garzik 875c6fd2807SJeff Garzik static inline unsigned int mv_hardport_from_port(unsigned int port) 876c6fd2807SJeff Garzik { 877c6fd2807SJeff Garzik return port & MV_PORT_MASK; 878c6fd2807SJeff Garzik } 879c6fd2807SJeff Garzik 8801cfd19aeSMark Lord /* 8811cfd19aeSMark Lord * Consolidate some rather tricky bit shift calculations. 8821cfd19aeSMark Lord * This is hot-path stuff, so not a function. 8831cfd19aeSMark Lord * Simple code, with two return values, so macro rather than inline. 8841cfd19aeSMark Lord * 8851cfd19aeSMark Lord * port is the sole input, in range 0..7. 8867368f919SMark Lord * shift is one output, for use with main_irq_cause / main_irq_mask registers. 8877368f919SMark Lord * hardport is the other output, in range 0..3. 8881cfd19aeSMark Lord * 8891cfd19aeSMark Lord * Note that port and hardport may be the same variable in some cases. 8901cfd19aeSMark Lord */ 8911cfd19aeSMark Lord #define MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport) \ 8921cfd19aeSMark Lord { \ 8931cfd19aeSMark Lord shift = mv_hc_from_port(port) * HC_SHIFT; \ 8941cfd19aeSMark Lord hardport = mv_hardport_from_port(port); \ 8951cfd19aeSMark Lord shift += hardport * 2; \ 8961cfd19aeSMark Lord } 8971cfd19aeSMark Lord 898352fab70SMark Lord static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) 899352fab70SMark Lord { 900cae5a29dSMark Lord return (base + SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 901352fab70SMark Lord } 902352fab70SMark Lord 903c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 904c6fd2807SJeff Garzik unsigned int port) 905c6fd2807SJeff Garzik { 906c6fd2807SJeff Garzik return mv_hc_base(base, mv_hc_from_port(port)); 907c6fd2807SJeff Garzik } 908c6fd2807SJeff Garzik 909c6fd2807SJeff Garzik static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) 910c6fd2807SJeff Garzik { 911c6fd2807SJeff Garzik return mv_hc_base_from_port(base, port) + 912c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ + 913c6fd2807SJeff Garzik (mv_hardport_from_port(port) * MV_PORT_REG_SZ); 914c6fd2807SJeff Garzik } 915c6fd2807SJeff Garzik 916e12bef50SMark Lord static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) 917e12bef50SMark Lord { 918e12bef50SMark Lord void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); 919e12bef50SMark Lord unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; 920e12bef50SMark Lord 921e12bef50SMark Lord return hc_mmio + ofs; 922e12bef50SMark Lord } 923e12bef50SMark Lord 924f351b2d6SSaeed Bishara static inline void __iomem *mv_host_base(struct ata_host *host) 925f351b2d6SSaeed Bishara { 926f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 927f351b2d6SSaeed Bishara return hpriv->base; 928f351b2d6SSaeed Bishara } 929f351b2d6SSaeed Bishara 930c6fd2807SJeff Garzik static inline void __iomem *mv_ap_base(struct ata_port *ap) 931c6fd2807SJeff Garzik { 932f351b2d6SSaeed Bishara return mv_port_base(mv_host_base(ap->host), ap->port_no); 933c6fd2807SJeff Garzik } 934c6fd2807SJeff Garzik 935cca3974eSJeff Garzik static inline int mv_get_hc_count(unsigned long port_flags) 936c6fd2807SJeff Garzik { 937cca3974eSJeff Garzik return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 938c6fd2807SJeff Garzik } 939c6fd2807SJeff Garzik 94008da1759SMark Lord /** 94108da1759SMark Lord * mv_save_cached_regs - (re-)initialize cached port registers 94208da1759SMark Lord * @ap: the port whose registers we are caching 94308da1759SMark Lord * 94408da1759SMark Lord * Initialize the local cache of port registers, 94508da1759SMark Lord * so that reading them over and over again can 94608da1759SMark Lord * be avoided on the hotter paths of this driver. 94708da1759SMark Lord * This saves a few microseconds each time we switch 94808da1759SMark Lord * to/from EDMA mode to perform (eg.) a drive cache flush. 94908da1759SMark Lord */ 95008da1759SMark Lord static void mv_save_cached_regs(struct ata_port *ap) 95108da1759SMark Lord { 95208da1759SMark Lord void __iomem *port_mmio = mv_ap_base(ap); 95308da1759SMark Lord struct mv_port_priv *pp = ap->private_data; 95408da1759SMark Lord 955cae5a29dSMark Lord pp->cached.fiscfg = readl(port_mmio + FISCFG); 956cae5a29dSMark Lord pp->cached.ltmode = readl(port_mmio + LTMODE); 957cae5a29dSMark Lord pp->cached.haltcond = readl(port_mmio + EDMA_HALTCOND); 958cae5a29dSMark Lord pp->cached.unknown_rsvd = readl(port_mmio + EDMA_UNKNOWN_RSVD); 95908da1759SMark Lord } 96008da1759SMark Lord 96108da1759SMark Lord /** 96208da1759SMark Lord * mv_write_cached_reg - write to a cached port register 96308da1759SMark Lord * @addr: hardware address of the register 96408da1759SMark Lord * @old: pointer to cached value of the register 96508da1759SMark Lord * @new: new value for the register 96608da1759SMark Lord * 96708da1759SMark Lord * Write a new value to a cached register, 96808da1759SMark Lord * but only if the value is different from before. 96908da1759SMark Lord */ 97008da1759SMark Lord static inline void mv_write_cached_reg(void __iomem *addr, u32 *old, u32 new) 97108da1759SMark Lord { 97208da1759SMark Lord if (new != *old) { 97312f3b6d7SMark Lord unsigned long laddr; 97408da1759SMark Lord *old = new; 97512f3b6d7SMark Lord /* 97612f3b6d7SMark Lord * Workaround for 88SX60x1-B2 FEr SATA#13: 97712f3b6d7SMark Lord * Read-after-write is needed to prevent generating 64-bit 97812f3b6d7SMark Lord * write cycles on the PCI bus for SATA interface registers 97912f3b6d7SMark Lord * at offsets ending in 0x4 or 0xc. 98012f3b6d7SMark Lord * 98112f3b6d7SMark Lord * Looks like a lot of fuss, but it avoids an unnecessary 98212f3b6d7SMark Lord * +1 usec read-after-write delay for unaffected registers. 98312f3b6d7SMark Lord */ 98412f3b6d7SMark Lord laddr = (long)addr & 0xffff; 98512f3b6d7SMark Lord if (laddr >= 0x300 && laddr <= 0x33c) { 98612f3b6d7SMark Lord laddr &= 0x000f; 98712f3b6d7SMark Lord if (laddr == 0x4 || laddr == 0xc) { 98812f3b6d7SMark Lord writelfl(new, addr); /* read after write */ 98912f3b6d7SMark Lord return; 99012f3b6d7SMark Lord } 99112f3b6d7SMark Lord } 99212f3b6d7SMark Lord writel(new, addr); /* unaffected by the errata */ 99308da1759SMark Lord } 99408da1759SMark Lord } 99508da1759SMark Lord 996c5d3e45aSJeff Garzik static void mv_set_edma_ptrs(void __iomem *port_mmio, 997c5d3e45aSJeff Garzik struct mv_host_priv *hpriv, 998c5d3e45aSJeff Garzik struct mv_port_priv *pp) 999c5d3e45aSJeff Garzik { 1000bdd4dddeSJeff Garzik u32 index; 1001bdd4dddeSJeff Garzik 1002c5d3e45aSJeff Garzik /* 1003c5d3e45aSJeff Garzik * initialize request queue 1004c5d3e45aSJeff Garzik */ 1005fcfb1f77SMark Lord pp->req_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */ 1006fcfb1f77SMark Lord index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT; 1007bdd4dddeSJeff Garzik 1008c5d3e45aSJeff Garzik WARN_ON(pp->crqb_dma & 0x3ff); 1009cae5a29dSMark Lord writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI); 1010bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index, 1011cae5a29dSMark Lord port_mmio + EDMA_REQ_Q_IN_PTR); 1012cae5a29dSMark Lord writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR); 1013c5d3e45aSJeff Garzik 1014c5d3e45aSJeff Garzik /* 1015c5d3e45aSJeff Garzik * initialize response queue 1016c5d3e45aSJeff Garzik */ 1017fcfb1f77SMark Lord pp->resp_idx &= MV_MAX_Q_DEPTH_MASK; /* paranoia */ 1018fcfb1f77SMark Lord index = pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT; 1019bdd4dddeSJeff Garzik 1020c5d3e45aSJeff Garzik WARN_ON(pp->crpb_dma & 0xff); 1021cae5a29dSMark Lord writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI); 1022cae5a29dSMark Lord writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR); 1023bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index, 1024cae5a29dSMark Lord port_mmio + EDMA_RSP_Q_OUT_PTR); 1025c5d3e45aSJeff Garzik } 1026c5d3e45aSJeff Garzik 10272b748a0aSMark Lord static void mv_write_main_irq_mask(u32 mask, struct mv_host_priv *hpriv) 10282b748a0aSMark Lord { 10292b748a0aSMark Lord /* 10302b748a0aSMark Lord * When writing to the main_irq_mask in hardware, 10312b748a0aSMark Lord * we must ensure exclusivity between the interrupt coalescing bits 10322b748a0aSMark Lord * and the corresponding individual port DONE_IRQ bits. 10332b748a0aSMark Lord * 10342b748a0aSMark Lord * Note that this register is really an "IRQ enable" register, 10352b748a0aSMark Lord * not an "IRQ mask" register as Marvell's naming might suggest. 10362b748a0aSMark Lord */ 10372b748a0aSMark Lord if (mask & (ALL_PORTS_COAL_DONE | PORTS_0_3_COAL_DONE)) 10382b748a0aSMark Lord mask &= ~DONE_IRQ_0_3; 10392b748a0aSMark Lord if (mask & (ALL_PORTS_COAL_DONE | PORTS_4_7_COAL_DONE)) 10402b748a0aSMark Lord mask &= ~DONE_IRQ_4_7; 10412b748a0aSMark Lord writelfl(mask, hpriv->main_irq_mask_addr); 10422b748a0aSMark Lord } 10432b748a0aSMark Lord 1044c4de573bSMark Lord static void mv_set_main_irq_mask(struct ata_host *host, 1045c4de573bSMark Lord u32 disable_bits, u32 enable_bits) 1046c4de573bSMark Lord { 1047c4de573bSMark Lord struct mv_host_priv *hpriv = host->private_data; 1048c4de573bSMark Lord u32 old_mask, new_mask; 1049c4de573bSMark Lord 105096e2c487SMark Lord old_mask = hpriv->main_irq_mask; 1051c4de573bSMark Lord new_mask = (old_mask & ~disable_bits) | enable_bits; 105296e2c487SMark Lord if (new_mask != old_mask) { 105396e2c487SMark Lord hpriv->main_irq_mask = new_mask; 10542b748a0aSMark Lord mv_write_main_irq_mask(new_mask, hpriv); 1055c4de573bSMark Lord } 105696e2c487SMark Lord } 1057c4de573bSMark Lord 1058c4de573bSMark Lord static void mv_enable_port_irqs(struct ata_port *ap, 1059c4de573bSMark Lord unsigned int port_bits) 1060c4de573bSMark Lord { 1061c4de573bSMark Lord unsigned int shift, hardport, port = ap->port_no; 1062c4de573bSMark Lord u32 disable_bits, enable_bits; 1063c4de573bSMark Lord 1064c4de573bSMark Lord MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport); 1065c4de573bSMark Lord 1066c4de573bSMark Lord disable_bits = (DONE_IRQ | ERR_IRQ) << shift; 1067c4de573bSMark Lord enable_bits = port_bits << shift; 1068c4de573bSMark Lord mv_set_main_irq_mask(ap->host, disable_bits, enable_bits); 1069c4de573bSMark Lord } 1070c4de573bSMark Lord 107100b81235SMark Lord static void mv_clear_and_enable_port_irqs(struct ata_port *ap, 107200b81235SMark Lord void __iomem *port_mmio, 107300b81235SMark Lord unsigned int port_irqs) 1074c6fd2807SJeff Garzik { 10750c58912eSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1076352fab70SMark Lord int hardport = mv_hardport_from_port(ap->port_no); 10770c58912eSMark Lord void __iomem *hc_mmio = mv_hc_base_from_port( 1078b0bccb18SMark Lord mv_host_base(ap->host), ap->port_no); 1079cae6edc3SMark Lord u32 hc_irq_cause; 10800c58912eSMark Lord 1081bdd4dddeSJeff Garzik /* clear EDMA event indicators, if any */ 1082cae5a29dSMark Lord writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE); 1083bdd4dddeSJeff Garzik 1084cae6edc3SMark Lord /* clear pending irq events */ 1085cae6edc3SMark Lord hc_irq_cause = ~((DEV_IRQ | DMA_IRQ) << hardport); 1086cae5a29dSMark Lord writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE); 10870c58912eSMark Lord 10880c58912eSMark Lord /* clear FIS IRQ Cause */ 1089e4006077SMark Lord if (IS_GEN_IIE(hpriv)) 1090cae5a29dSMark Lord writelfl(0, port_mmio + FIS_IRQ_CAUSE); 10910c58912eSMark Lord 109200b81235SMark Lord mv_enable_port_irqs(ap, port_irqs); 109300b81235SMark Lord } 109400b81235SMark Lord 10952b748a0aSMark Lord static void mv_set_irq_coalescing(struct ata_host *host, 10962b748a0aSMark Lord unsigned int count, unsigned int usecs) 10972b748a0aSMark Lord { 10982b748a0aSMark Lord struct mv_host_priv *hpriv = host->private_data; 10992b748a0aSMark Lord void __iomem *mmio = hpriv->base, *hc_mmio; 11002b748a0aSMark Lord u32 coal_enable = 0; 11012b748a0aSMark Lord unsigned long flags; 11026abf4678SMark Lord unsigned int clks, is_dual_hc = hpriv->n_ports > MV_PORTS_PER_HC; 11032b748a0aSMark Lord const u32 coal_disable = PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE | 11042b748a0aSMark Lord ALL_PORTS_COAL_DONE; 11052b748a0aSMark Lord 11062b748a0aSMark Lord /* Disable IRQ coalescing if either threshold is zero */ 11072b748a0aSMark Lord if (!usecs || !count) { 11082b748a0aSMark Lord clks = count = 0; 11092b748a0aSMark Lord } else { 11102b748a0aSMark Lord /* Respect maximum limits of the hardware */ 11112b748a0aSMark Lord clks = usecs * COAL_CLOCKS_PER_USEC; 11122b748a0aSMark Lord if (clks > MAX_COAL_TIME_THRESHOLD) 11132b748a0aSMark Lord clks = MAX_COAL_TIME_THRESHOLD; 11142b748a0aSMark Lord if (count > MAX_COAL_IO_COUNT) 11152b748a0aSMark Lord count = MAX_COAL_IO_COUNT; 11162b748a0aSMark Lord } 11172b748a0aSMark Lord 11182b748a0aSMark Lord spin_lock_irqsave(&host->lock, flags); 11196abf4678SMark Lord mv_set_main_irq_mask(host, coal_disable, 0); 11202b748a0aSMark Lord 11216abf4678SMark Lord if (is_dual_hc && !IS_GEN_I(hpriv)) { 11222b748a0aSMark Lord /* 11236abf4678SMark Lord * GEN_II/GEN_IIE with dual host controllers: 11246abf4678SMark Lord * one set of global thresholds for the entire chip. 11252b748a0aSMark Lord */ 1126cae5a29dSMark Lord writel(clks, mmio + IRQ_COAL_TIME_THRESHOLD); 1127cae5a29dSMark Lord writel(count, mmio + IRQ_COAL_IO_THRESHOLD); 11282b748a0aSMark Lord /* clear leftover coal IRQ bit */ 1129cae5a29dSMark Lord writel(~ALL_PORTS_COAL_IRQ, mmio + IRQ_COAL_CAUSE); 11306abf4678SMark Lord if (count) 11312b748a0aSMark Lord coal_enable = ALL_PORTS_COAL_DONE; 11326abf4678SMark Lord clks = count = 0; /* force clearing of regular regs below */ 11332b748a0aSMark Lord } 11346abf4678SMark Lord 11352b748a0aSMark Lord /* 11362b748a0aSMark Lord * All chips: independent thresholds for each HC on the chip. 11372b748a0aSMark Lord */ 11382b748a0aSMark Lord hc_mmio = mv_hc_base_from_port(mmio, 0); 1139cae5a29dSMark Lord writel(clks, hc_mmio + HC_IRQ_COAL_TIME_THRESHOLD); 1140cae5a29dSMark Lord writel(count, hc_mmio + HC_IRQ_COAL_IO_THRESHOLD); 1141cae5a29dSMark Lord writel(~HC_COAL_IRQ, hc_mmio + HC_IRQ_CAUSE); 11426abf4678SMark Lord if (count) 11432b748a0aSMark Lord coal_enable |= PORTS_0_3_COAL_DONE; 11446abf4678SMark Lord if (is_dual_hc) { 11452b748a0aSMark Lord hc_mmio = mv_hc_base_from_port(mmio, MV_PORTS_PER_HC); 1146cae5a29dSMark Lord writel(clks, hc_mmio + HC_IRQ_COAL_TIME_THRESHOLD); 1147cae5a29dSMark Lord writel(count, hc_mmio + HC_IRQ_COAL_IO_THRESHOLD); 1148cae5a29dSMark Lord writel(~HC_COAL_IRQ, hc_mmio + HC_IRQ_CAUSE); 11496abf4678SMark Lord if (count) 11502b748a0aSMark Lord coal_enable |= PORTS_4_7_COAL_DONE; 11512b748a0aSMark Lord } 11522b748a0aSMark Lord 11536abf4678SMark Lord mv_set_main_irq_mask(host, 0, coal_enable); 11542b748a0aSMark Lord spin_unlock_irqrestore(&host->lock, flags); 11552b748a0aSMark Lord } 11562b748a0aSMark Lord 115700b81235SMark Lord /** 115800b81235SMark Lord * mv_start_edma - Enable eDMA engine 115900b81235SMark Lord * @base: port base address 116000b81235SMark Lord * @pp: port private data 116100b81235SMark Lord * 116200b81235SMark Lord * Verify the local cache of the eDMA state is accurate with a 116300b81235SMark Lord * WARN_ON. 116400b81235SMark Lord * 116500b81235SMark Lord * LOCKING: 116600b81235SMark Lord * Inherited from caller. 116700b81235SMark Lord */ 116800b81235SMark Lord static void mv_start_edma(struct ata_port *ap, void __iomem *port_mmio, 116900b81235SMark Lord struct mv_port_priv *pp, u8 protocol) 117000b81235SMark Lord { 117100b81235SMark Lord int want_ncq = (protocol == ATA_PROT_NCQ); 117200b81235SMark Lord 117300b81235SMark Lord if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 117400b81235SMark Lord int using_ncq = ((pp->pp_flags & MV_PP_FLAG_NCQ_EN) != 0); 117500b81235SMark Lord if (want_ncq != using_ncq) 117600b81235SMark Lord mv_stop_edma(ap); 117700b81235SMark Lord } 117800b81235SMark Lord if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 117900b81235SMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 118000b81235SMark Lord 118100b81235SMark Lord mv_edma_cfg(ap, want_ncq, 1); 118200b81235SMark Lord 1183f630d562SMark Lord mv_set_edma_ptrs(port_mmio, hpriv, pp); 118400b81235SMark Lord mv_clear_and_enable_port_irqs(ap, port_mmio, DONE_IRQ|ERR_IRQ); 1185bdd4dddeSJeff Garzik 1186cae5a29dSMark Lord writelfl(EDMA_EN, port_mmio + EDMA_CMD); 1187c6fd2807SJeff Garzik pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 1188c6fd2807SJeff Garzik } 1189c6fd2807SJeff Garzik } 1190c6fd2807SJeff Garzik 11919b2c4e0bSMark Lord static void mv_wait_for_edma_empty_idle(struct ata_port *ap) 11929b2c4e0bSMark Lord { 11939b2c4e0bSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 11949b2c4e0bSMark Lord const u32 empty_idle = (EDMA_STATUS_CACHE_EMPTY | EDMA_STATUS_IDLE); 11959b2c4e0bSMark Lord const int per_loop = 5, timeout = (15 * 1000 / per_loop); 11969b2c4e0bSMark Lord int i; 11979b2c4e0bSMark Lord 11989b2c4e0bSMark Lord /* 11999b2c4e0bSMark Lord * Wait for the EDMA engine to finish transactions in progress. 1200c46938ccSMark Lord * No idea what a good "timeout" value might be, but measurements 1201c46938ccSMark Lord * indicate that it often requires hundreds of microseconds 1202c46938ccSMark Lord * with two drives in-use. So we use the 15msec value above 1203c46938ccSMark Lord * as a rough guess at what even more drives might require. 12049b2c4e0bSMark Lord */ 12059b2c4e0bSMark Lord for (i = 0; i < timeout; ++i) { 1206cae5a29dSMark Lord u32 edma_stat = readl(port_mmio + EDMA_STATUS); 12079b2c4e0bSMark Lord if ((edma_stat & empty_idle) == empty_idle) 12089b2c4e0bSMark Lord break; 12099b2c4e0bSMark Lord udelay(per_loop); 12109b2c4e0bSMark Lord } 1211a9a79dfeSJoe Perches /* ata_port_info(ap, "%s: %u+ usecs\n", __func__, i); */ 12129b2c4e0bSMark Lord } 12139b2c4e0bSMark Lord 1214c6fd2807SJeff Garzik /** 1215e12bef50SMark Lord * mv_stop_edma_engine - Disable eDMA engine 1216b562468cSMark Lord * @port_mmio: io base address 1217c6fd2807SJeff Garzik * 1218c6fd2807SJeff Garzik * LOCKING: 1219c6fd2807SJeff Garzik * Inherited from caller. 1220c6fd2807SJeff Garzik */ 1221b562468cSMark Lord static int mv_stop_edma_engine(void __iomem *port_mmio) 1222c6fd2807SJeff Garzik { 1223b562468cSMark Lord int i; 1224c6fd2807SJeff Garzik 1225b562468cSMark Lord /* Disable eDMA. The disable bit auto clears. */ 1226cae5a29dSMark Lord writelfl(EDMA_DS, port_mmio + EDMA_CMD); 1227c6fd2807SJeff Garzik 1228b562468cSMark Lord /* Wait for the chip to confirm eDMA is off. */ 1229b562468cSMark Lord for (i = 10000; i > 0; i--) { 1230cae5a29dSMark Lord u32 reg = readl(port_mmio + EDMA_CMD); 12314537deb5SJeff Garzik if (!(reg & EDMA_EN)) 1232b562468cSMark Lord return 0; 1233b562468cSMark Lord udelay(10); 1234c6fd2807SJeff Garzik } 1235b562468cSMark Lord return -EIO; 1236c6fd2807SJeff Garzik } 1237c6fd2807SJeff Garzik 1238e12bef50SMark Lord static int mv_stop_edma(struct ata_port *ap) 1239c6fd2807SJeff Garzik { 1240c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1241c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 124266e57a2cSMark Lord int err = 0; 1243c6fd2807SJeff Garzik 1244b562468cSMark Lord if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) 1245b562468cSMark Lord return 0; 1246c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 12479b2c4e0bSMark Lord mv_wait_for_edma_empty_idle(ap); 1248b562468cSMark Lord if (mv_stop_edma_engine(port_mmio)) { 1249a9a79dfeSJoe Perches ata_port_err(ap, "Unable to stop eDMA\n"); 125066e57a2cSMark Lord err = -EIO; 1251c6fd2807SJeff Garzik } 125266e57a2cSMark Lord mv_edma_cfg(ap, 0, 0); 125366e57a2cSMark Lord return err; 12540ea9e179SJeff Garzik } 12550ea9e179SJeff Garzik 1256c6fd2807SJeff Garzik #ifdef ATA_DEBUG 1257c6fd2807SJeff Garzik static void mv_dump_mem(void __iomem *start, unsigned bytes) 1258c6fd2807SJeff Garzik { 1259c6fd2807SJeff Garzik int b, w; 1260c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 1261c6fd2807SJeff Garzik DPRINTK("%p: ", start + b); 1262c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 1263c6fd2807SJeff Garzik printk("%08x ", readl(start + b)); 1264c6fd2807SJeff Garzik b += sizeof(u32); 1265c6fd2807SJeff Garzik } 1266c6fd2807SJeff Garzik printk("\n"); 1267c6fd2807SJeff Garzik } 1268c6fd2807SJeff Garzik } 1269c6fd2807SJeff Garzik #endif 127013b74085SAndrew Lunn #if defined(ATA_DEBUG) || defined(CONFIG_PCI) 1271c6fd2807SJeff Garzik static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes) 1272c6fd2807SJeff Garzik { 1273c6fd2807SJeff Garzik #ifdef ATA_DEBUG 1274c6fd2807SJeff Garzik int b, w; 1275c6fd2807SJeff Garzik u32 dw; 1276c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 1277c6fd2807SJeff Garzik DPRINTK("%02x: ", b); 1278c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 1279c6fd2807SJeff Garzik (void) pci_read_config_dword(pdev, b, &dw); 1280c6fd2807SJeff Garzik printk("%08x ", dw); 1281c6fd2807SJeff Garzik b += sizeof(u32); 1282c6fd2807SJeff Garzik } 1283c6fd2807SJeff Garzik printk("\n"); 1284c6fd2807SJeff Garzik } 1285c6fd2807SJeff Garzik #endif 1286c6fd2807SJeff Garzik } 128713b74085SAndrew Lunn #endif 1288c6fd2807SJeff Garzik static void mv_dump_all_regs(void __iomem *mmio_base, int port, 1289c6fd2807SJeff Garzik struct pci_dev *pdev) 1290c6fd2807SJeff Garzik { 1291c6fd2807SJeff Garzik #ifdef ATA_DEBUG 1292c6fd2807SJeff Garzik void __iomem *hc_base = mv_hc_base(mmio_base, 1293c6fd2807SJeff Garzik port >> MV_PORT_HC_SHIFT); 1294c6fd2807SJeff Garzik void __iomem *port_base; 1295c6fd2807SJeff Garzik int start_port, num_ports, p, start_hc, num_hcs, hc; 1296c6fd2807SJeff Garzik 1297c6fd2807SJeff Garzik if (0 > port) { 1298c6fd2807SJeff Garzik start_hc = start_port = 0; 1299c6fd2807SJeff Garzik num_ports = 8; /* shld be benign for 4 port devs */ 1300c6fd2807SJeff Garzik num_hcs = 2; 1301c6fd2807SJeff Garzik } else { 1302c6fd2807SJeff Garzik start_hc = port >> MV_PORT_HC_SHIFT; 1303c6fd2807SJeff Garzik start_port = port; 1304c6fd2807SJeff Garzik num_ports = num_hcs = 1; 1305c6fd2807SJeff Garzik } 1306c6fd2807SJeff Garzik DPRINTK("All registers for port(s) %u-%u:\n", start_port, 1307c6fd2807SJeff Garzik num_ports > 1 ? num_ports - 1 : start_port); 1308c6fd2807SJeff Garzik 1309c6fd2807SJeff Garzik if (NULL != pdev) { 1310c6fd2807SJeff Garzik DPRINTK("PCI config space regs:\n"); 1311c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 1312c6fd2807SJeff Garzik } 1313c6fd2807SJeff Garzik DPRINTK("PCI regs:\n"); 1314c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xc00, 0x3c); 1315c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xd00, 0x34); 1316c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xf00, 0x4); 1317c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0x1d00, 0x6c); 1318c6fd2807SJeff Garzik for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 1319c6fd2807SJeff Garzik hc_base = mv_hc_base(mmio_base, hc); 1320c6fd2807SJeff Garzik DPRINTK("HC regs (HC %i):\n", hc); 1321c6fd2807SJeff Garzik mv_dump_mem(hc_base, 0x1c); 1322c6fd2807SJeff Garzik } 1323c6fd2807SJeff Garzik for (p = start_port; p < start_port + num_ports; p++) { 1324c6fd2807SJeff Garzik port_base = mv_port_base(mmio_base, p); 1325c6fd2807SJeff Garzik DPRINTK("EDMA regs (port %i):\n", p); 1326c6fd2807SJeff Garzik mv_dump_mem(port_base, 0x54); 1327c6fd2807SJeff Garzik DPRINTK("SATA regs (port %i):\n", p); 1328c6fd2807SJeff Garzik mv_dump_mem(port_base+0x300, 0x60); 1329c6fd2807SJeff Garzik } 1330c6fd2807SJeff Garzik #endif 1331c6fd2807SJeff Garzik } 1332c6fd2807SJeff Garzik 1333c6fd2807SJeff Garzik static unsigned int mv_scr_offset(unsigned int sc_reg_in) 1334c6fd2807SJeff Garzik { 1335c6fd2807SJeff Garzik unsigned int ofs; 1336c6fd2807SJeff Garzik 1337c6fd2807SJeff Garzik switch (sc_reg_in) { 1338c6fd2807SJeff Garzik case SCR_STATUS: 1339c6fd2807SJeff Garzik case SCR_CONTROL: 1340c6fd2807SJeff Garzik case SCR_ERROR: 1341cae5a29dSMark Lord ofs = SATA_STATUS + (sc_reg_in * sizeof(u32)); 1342c6fd2807SJeff Garzik break; 1343c6fd2807SJeff Garzik case SCR_ACTIVE: 1344cae5a29dSMark Lord ofs = SATA_ACTIVE; /* active is not with the others */ 1345c6fd2807SJeff Garzik break; 1346c6fd2807SJeff Garzik default: 1347c6fd2807SJeff Garzik ofs = 0xffffffffU; 1348c6fd2807SJeff Garzik break; 1349c6fd2807SJeff Garzik } 1350c6fd2807SJeff Garzik return ofs; 1351c6fd2807SJeff Garzik } 1352c6fd2807SJeff Garzik 135382ef04fbSTejun Heo static int mv_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val) 1354c6fd2807SJeff Garzik { 1355c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1356c6fd2807SJeff Garzik 1357da3dbb17STejun Heo if (ofs != 0xffffffffU) { 135882ef04fbSTejun Heo *val = readl(mv_ap_base(link->ap) + ofs); 1359da3dbb17STejun Heo return 0; 1360da3dbb17STejun Heo } else 1361da3dbb17STejun Heo return -EINVAL; 1362c6fd2807SJeff Garzik } 1363c6fd2807SJeff Garzik 136482ef04fbSTejun Heo static int mv_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val) 1365c6fd2807SJeff Garzik { 1366c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1367c6fd2807SJeff Garzik 1368da3dbb17STejun Heo if (ofs != 0xffffffffU) { 136920091773SMark Lord void __iomem *addr = mv_ap_base(link->ap) + ofs; 13709013d64eSLior Amsalem struct mv_host_priv *hpriv = link->ap->host->private_data; 137120091773SMark Lord if (sc_reg_in == SCR_CONTROL) { 137220091773SMark Lord /* 137320091773SMark Lord * Workaround for 88SX60x1 FEr SATA#26: 137420091773SMark Lord * 137525985edcSLucas De Marchi * COMRESETs have to take care not to accidentally 137620091773SMark Lord * put the drive to sleep when writing SCR_CONTROL. 137720091773SMark Lord * Setting bits 12..15 prevents this problem. 137820091773SMark Lord * 137920091773SMark Lord * So if we see an outbound COMMRESET, set those bits. 138020091773SMark Lord * Ditto for the followup write that clears the reset. 138120091773SMark Lord * 138220091773SMark Lord * The proprietary driver does this for 138320091773SMark Lord * all chip versions, and so do we. 138420091773SMark Lord */ 138520091773SMark Lord if ((val & 0xf) == 1 || (readl(addr) & 0xf) == 1) 138620091773SMark Lord val |= 0xf000; 13879013d64eSLior Amsalem 13889013d64eSLior Amsalem if (hpriv->hp_flags & MV_HP_FIX_LP_PHY_CTL) { 13899013d64eSLior Amsalem void __iomem *lp_phy_addr = 13909013d64eSLior Amsalem mv_ap_base(link->ap) + LP_PHY_CTL; 13919013d64eSLior Amsalem /* 13929013d64eSLior Amsalem * Set PHY speed according to SControl speed. 13939013d64eSLior Amsalem */ 13949013d64eSLior Amsalem if ((val & 0xf0) == 0x10) 13959013d64eSLior Amsalem writelfl(0x7, lp_phy_addr); 13969013d64eSLior Amsalem else 13979013d64eSLior Amsalem writelfl(0x227, lp_phy_addr); 13989013d64eSLior Amsalem } 139920091773SMark Lord } 140020091773SMark Lord writelfl(val, addr); 1401da3dbb17STejun Heo return 0; 1402da3dbb17STejun Heo } else 1403da3dbb17STejun Heo return -EINVAL; 1404c6fd2807SJeff Garzik } 1405c6fd2807SJeff Garzik 1406f273827eSMark Lord static void mv6_dev_config(struct ata_device *adev) 1407f273827eSMark Lord { 1408f273827eSMark Lord /* 1409e49856d8SMark Lord * Deal with Gen-II ("mv6") hardware quirks/restrictions: 1410e49856d8SMark Lord * 1411e49856d8SMark Lord * Gen-II does not support NCQ over a port multiplier 1412e49856d8SMark Lord * (no FIS-based switching). 1413f273827eSMark Lord */ 1414e49856d8SMark Lord if (adev->flags & ATA_DFLAG_NCQ) { 1415352fab70SMark Lord if (sata_pmp_attached(adev->link->ap)) { 1416e49856d8SMark Lord adev->flags &= ~ATA_DFLAG_NCQ; 1417a9a79dfeSJoe Perches ata_dev_info(adev, 1418352fab70SMark Lord "NCQ disabled for command-based switching\n"); 1419352fab70SMark Lord } 1420f273827eSMark Lord } 1421e49856d8SMark Lord } 1422f273827eSMark Lord 14233e4a1391SMark Lord static int mv_qc_defer(struct ata_queued_cmd *qc) 14243e4a1391SMark Lord { 14253e4a1391SMark Lord struct ata_link *link = qc->dev->link; 14263e4a1391SMark Lord struct ata_port *ap = link->ap; 14273e4a1391SMark Lord struct mv_port_priv *pp = ap->private_data; 14283e4a1391SMark Lord 14293e4a1391SMark Lord /* 143029d187bbSMark Lord * Don't allow new commands if we're in a delayed EH state 143129d187bbSMark Lord * for NCQ and/or FIS-based switching. 143229d187bbSMark Lord */ 143329d187bbSMark Lord if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH) 143429d187bbSMark Lord return ATA_DEFER_PORT; 1435159a7ff7SGwendal Grignou 1436159a7ff7SGwendal Grignou /* PIO commands need exclusive link: no other commands [DMA or PIO] 1437159a7ff7SGwendal Grignou * can run concurrently. 1438159a7ff7SGwendal Grignou * set excl_link when we want to send a PIO command in DMA mode 1439159a7ff7SGwendal Grignou * or a non-NCQ command in NCQ mode. 1440159a7ff7SGwendal Grignou * When we receive a command from that link, and there are no 1441159a7ff7SGwendal Grignou * outstanding commands, mark a flag to clear excl_link and let 1442159a7ff7SGwendal Grignou * the command go through. 1443159a7ff7SGwendal Grignou */ 1444159a7ff7SGwendal Grignou if (unlikely(ap->excl_link)) { 1445159a7ff7SGwendal Grignou if (link == ap->excl_link) { 1446159a7ff7SGwendal Grignou if (ap->nr_active_links) 1447159a7ff7SGwendal Grignou return ATA_DEFER_PORT; 1448159a7ff7SGwendal Grignou qc->flags |= ATA_QCFLAG_CLEAR_EXCL; 1449159a7ff7SGwendal Grignou return 0; 1450159a7ff7SGwendal Grignou } else 1451159a7ff7SGwendal Grignou return ATA_DEFER_PORT; 1452159a7ff7SGwendal Grignou } 1453159a7ff7SGwendal Grignou 145429d187bbSMark Lord /* 14553e4a1391SMark Lord * If the port is completely idle, then allow the new qc. 14563e4a1391SMark Lord */ 14573e4a1391SMark Lord if (ap->nr_active_links == 0) 14583e4a1391SMark Lord return 0; 14593e4a1391SMark Lord 14603e4a1391SMark Lord /* 14614bdee6c5STejun Heo * The port is operating in host queuing mode (EDMA) with NCQ 14624bdee6c5STejun Heo * enabled, allow multiple NCQ commands. EDMA also allows 14634bdee6c5STejun Heo * queueing multiple DMA commands but libata core currently 14644bdee6c5STejun Heo * doesn't allow it. 14653e4a1391SMark Lord */ 14664bdee6c5STejun Heo if ((pp->pp_flags & MV_PP_FLAG_EDMA_EN) && 1467159a7ff7SGwendal Grignou (pp->pp_flags & MV_PP_FLAG_NCQ_EN)) { 1468159a7ff7SGwendal Grignou if (ata_is_ncq(qc->tf.protocol)) 14693e4a1391SMark Lord return 0; 1470159a7ff7SGwendal Grignou else { 1471159a7ff7SGwendal Grignou ap->excl_link = link; 1472159a7ff7SGwendal Grignou return ATA_DEFER_PORT; 1473159a7ff7SGwendal Grignou } 1474159a7ff7SGwendal Grignou } 14754bdee6c5STejun Heo 14763e4a1391SMark Lord return ATA_DEFER_PORT; 14773e4a1391SMark Lord } 14783e4a1391SMark Lord 147908da1759SMark Lord static void mv_config_fbs(struct ata_port *ap, int want_ncq, int want_fbs) 1480e49856d8SMark Lord { 148108da1759SMark Lord struct mv_port_priv *pp = ap->private_data; 148208da1759SMark Lord void __iomem *port_mmio; 148300f42eabSMark Lord 148408da1759SMark Lord u32 fiscfg, *old_fiscfg = &pp->cached.fiscfg; 148508da1759SMark Lord u32 ltmode, *old_ltmode = &pp->cached.ltmode; 148608da1759SMark Lord u32 haltcond, *old_haltcond = &pp->cached.haltcond; 148700f42eabSMark Lord 148808da1759SMark Lord ltmode = *old_ltmode & ~LTMODE_BIT8; 148908da1759SMark Lord haltcond = *old_haltcond | EDMA_ERR_DEV; 149000f42eabSMark Lord 149100f42eabSMark Lord if (want_fbs) { 149208da1759SMark Lord fiscfg = *old_fiscfg | FISCFG_SINGLE_SYNC; 149308da1759SMark Lord ltmode = *old_ltmode | LTMODE_BIT8; 14944c299ca3SMark Lord if (want_ncq) 149508da1759SMark Lord haltcond &= ~EDMA_ERR_DEV; 14964c299ca3SMark Lord else 149708da1759SMark Lord fiscfg |= FISCFG_WAIT_DEV_ERR; 149808da1759SMark Lord } else { 149908da1759SMark Lord fiscfg = *old_fiscfg & ~(FISCFG_SINGLE_SYNC | FISCFG_WAIT_DEV_ERR); 1500e49856d8SMark Lord } 150100f42eabSMark Lord 150208da1759SMark Lord port_mmio = mv_ap_base(ap); 1503cae5a29dSMark Lord mv_write_cached_reg(port_mmio + FISCFG, old_fiscfg, fiscfg); 1504cae5a29dSMark Lord mv_write_cached_reg(port_mmio + LTMODE, old_ltmode, ltmode); 1505cae5a29dSMark Lord mv_write_cached_reg(port_mmio + EDMA_HALTCOND, old_haltcond, haltcond); 1506e49856d8SMark Lord } 1507c6fd2807SJeff Garzik 1508dd2890f6SMark Lord static void mv_60x1_errata_sata25(struct ata_port *ap, int want_ncq) 1509dd2890f6SMark Lord { 1510dd2890f6SMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1511dd2890f6SMark Lord u32 old, new; 1512dd2890f6SMark Lord 1513dd2890f6SMark Lord /* workaround for 88SX60x1 FEr SATA#25 (part 1) */ 1514cae5a29dSMark Lord old = readl(hpriv->base + GPIO_PORT_CTL); 1515dd2890f6SMark Lord if (want_ncq) 1516dd2890f6SMark Lord new = old | (1 << 22); 1517dd2890f6SMark Lord else 1518dd2890f6SMark Lord new = old & ~(1 << 22); 1519dd2890f6SMark Lord if (new != old) 1520cae5a29dSMark Lord writel(new, hpriv->base + GPIO_PORT_CTL); 1521dd2890f6SMark Lord } 1522dd2890f6SMark Lord 1523c01e8a23SMark Lord /** 1524c01e8a23SMark Lord * mv_bmdma_enable - set a magic bit on GEN_IIE to allow bmdma 1525c01e8a23SMark Lord * @ap: Port being initialized 1526c01e8a23SMark Lord * 1527c01e8a23SMark Lord * There are two DMA modes on these chips: basic DMA, and EDMA. 1528c01e8a23SMark Lord * 1529c01e8a23SMark Lord * Bit-0 of the "EDMA RESERVED" register enables/disables use 1530c01e8a23SMark Lord * of basic DMA on the GEN_IIE versions of the chips. 1531c01e8a23SMark Lord * 1532c01e8a23SMark Lord * This bit survives EDMA resets, and must be set for basic DMA 1533c01e8a23SMark Lord * to function, and should be cleared when EDMA is active. 1534c01e8a23SMark Lord */ 1535c01e8a23SMark Lord static void mv_bmdma_enable_iie(struct ata_port *ap, int enable_bmdma) 1536c01e8a23SMark Lord { 1537c01e8a23SMark Lord struct mv_port_priv *pp = ap->private_data; 1538c01e8a23SMark Lord u32 new, *old = &pp->cached.unknown_rsvd; 1539c01e8a23SMark Lord 1540c01e8a23SMark Lord if (enable_bmdma) 1541c01e8a23SMark Lord new = *old | 1; 1542c01e8a23SMark Lord else 1543c01e8a23SMark Lord new = *old & ~1; 1544cae5a29dSMark Lord mv_write_cached_reg(mv_ap_base(ap) + EDMA_UNKNOWN_RSVD, old, new); 1545c01e8a23SMark Lord } 1546c01e8a23SMark Lord 1547000b344fSMark Lord /* 1548000b344fSMark Lord * SOC chips have an issue whereby the HDD LEDs don't always blink 1549000b344fSMark Lord * during I/O when NCQ is enabled. Enabling a special "LED blink" mode 1550000b344fSMark Lord * of the SOC takes care of it, generating a steady blink rate when 1551000b344fSMark Lord * any drive on the chip is active. 1552000b344fSMark Lord * 1553000b344fSMark Lord * Unfortunately, the blink mode is a global hardware setting for the SOC, 1554000b344fSMark Lord * so we must use it whenever at least one port on the SOC has NCQ enabled. 1555000b344fSMark Lord * 1556000b344fSMark Lord * We turn "LED blink" off when NCQ is not in use anywhere, because the normal 1557000b344fSMark Lord * LED operation works then, and provides better (more accurate) feedback. 1558000b344fSMark Lord * 1559000b344fSMark Lord * Note that this code assumes that an SOC never has more than one HC onboard. 1560000b344fSMark Lord */ 1561000b344fSMark Lord static void mv_soc_led_blink_enable(struct ata_port *ap) 1562000b344fSMark Lord { 1563000b344fSMark Lord struct ata_host *host = ap->host; 1564000b344fSMark Lord struct mv_host_priv *hpriv = host->private_data; 1565000b344fSMark Lord void __iomem *hc_mmio; 1566000b344fSMark Lord u32 led_ctrl; 1567000b344fSMark Lord 1568000b344fSMark Lord if (hpriv->hp_flags & MV_HP_QUIRK_LED_BLINK_EN) 1569000b344fSMark Lord return; 1570000b344fSMark Lord hpriv->hp_flags |= MV_HP_QUIRK_LED_BLINK_EN; 1571000b344fSMark Lord hc_mmio = mv_hc_base_from_port(mv_host_base(host), ap->port_no); 1572cae5a29dSMark Lord led_ctrl = readl(hc_mmio + SOC_LED_CTRL); 1573cae5a29dSMark Lord writel(led_ctrl | SOC_LED_CTRL_BLINK, hc_mmio + SOC_LED_CTRL); 1574000b344fSMark Lord } 1575000b344fSMark Lord 1576000b344fSMark Lord static void mv_soc_led_blink_disable(struct ata_port *ap) 1577000b344fSMark Lord { 1578000b344fSMark Lord struct ata_host *host = ap->host; 1579000b344fSMark Lord struct mv_host_priv *hpriv = host->private_data; 1580000b344fSMark Lord void __iomem *hc_mmio; 1581000b344fSMark Lord u32 led_ctrl; 1582000b344fSMark Lord unsigned int port; 1583000b344fSMark Lord 1584000b344fSMark Lord if (!(hpriv->hp_flags & MV_HP_QUIRK_LED_BLINK_EN)) 1585000b344fSMark Lord return; 1586000b344fSMark Lord 1587000b344fSMark Lord /* disable led-blink only if no ports are using NCQ */ 1588000b344fSMark Lord for (port = 0; port < hpriv->n_ports; port++) { 1589000b344fSMark Lord struct ata_port *this_ap = host->ports[port]; 1590000b344fSMark Lord struct mv_port_priv *pp = this_ap->private_data; 1591000b344fSMark Lord 1592000b344fSMark Lord if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) 1593000b344fSMark Lord return; 1594000b344fSMark Lord } 1595000b344fSMark Lord 1596000b344fSMark Lord hpriv->hp_flags &= ~MV_HP_QUIRK_LED_BLINK_EN; 1597000b344fSMark Lord hc_mmio = mv_hc_base_from_port(mv_host_base(host), ap->port_no); 1598cae5a29dSMark Lord led_ctrl = readl(hc_mmio + SOC_LED_CTRL); 1599cae5a29dSMark Lord writel(led_ctrl & ~SOC_LED_CTRL_BLINK, hc_mmio + SOC_LED_CTRL); 1600000b344fSMark Lord } 1601000b344fSMark Lord 160200b81235SMark Lord static void mv_edma_cfg(struct ata_port *ap, int want_ncq, int want_edma) 1603c6fd2807SJeff Garzik { 1604c6fd2807SJeff Garzik u32 cfg; 1605e12bef50SMark Lord struct mv_port_priv *pp = ap->private_data; 1606e12bef50SMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1607e12bef50SMark Lord void __iomem *port_mmio = mv_ap_base(ap); 1608c6fd2807SJeff Garzik 1609c6fd2807SJeff Garzik /* set up non-NCQ EDMA configuration */ 1610c6fd2807SJeff Garzik cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */ 1611d16ab3f6SMark Lord pp->pp_flags &= 1612d16ab3f6SMark Lord ~(MV_PP_FLAG_FBS_EN | MV_PP_FLAG_NCQ_EN | MV_PP_FLAG_FAKE_ATA_BUSY); 1613c6fd2807SJeff Garzik 1614c6fd2807SJeff Garzik if (IS_GEN_I(hpriv)) 1615c6fd2807SJeff Garzik cfg |= (1 << 8); /* enab config burst size mask */ 1616c6fd2807SJeff Garzik 1617dd2890f6SMark Lord else if (IS_GEN_II(hpriv)) { 1618c6fd2807SJeff Garzik cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 1619dd2890f6SMark Lord mv_60x1_errata_sata25(ap, want_ncq); 1620c6fd2807SJeff Garzik 1621dd2890f6SMark Lord } else if (IS_GEN_IIE(hpriv)) { 162200f42eabSMark Lord int want_fbs = sata_pmp_attached(ap); 162300f42eabSMark Lord /* 162400f42eabSMark Lord * Possible future enhancement: 162500f42eabSMark Lord * 162600f42eabSMark Lord * The chip can use FBS with non-NCQ, if we allow it, 162700f42eabSMark Lord * But first we need to have the error handling in place 162800f42eabSMark Lord * for this mode (datasheet section 7.3.15.4.2.3). 162900f42eabSMark Lord * So disallow non-NCQ FBS for now. 163000f42eabSMark Lord */ 163100f42eabSMark Lord want_fbs &= want_ncq; 163200f42eabSMark Lord 163308da1759SMark Lord mv_config_fbs(ap, want_ncq, want_fbs); 163400f42eabSMark Lord 163500f42eabSMark Lord if (want_fbs) { 163600f42eabSMark Lord pp->pp_flags |= MV_PP_FLAG_FBS_EN; 163700f42eabSMark Lord cfg |= EDMA_CFG_EDMA_FBS; /* FIS-based switching */ 163800f42eabSMark Lord } 163900f42eabSMark Lord 1640e728eabeSJeff Garzik cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */ 164100b81235SMark Lord if (want_edma) { 1642e728eabeSJeff Garzik cfg |= (1 << 22); /* enab 4-entry host queue cache */ 16431f398472SMark Lord if (!IS_SOC(hpriv)) 1644c6fd2807SJeff Garzik cfg |= (1 << 18); /* enab early completion */ 164500b81235SMark Lord } 1646616d4a98SMark Lord if (hpriv->hp_flags & MV_HP_CUT_THROUGH) 1647616d4a98SMark Lord cfg |= (1 << 17); /* enab cut-thru (dis stor&forwrd) */ 1648c01e8a23SMark Lord mv_bmdma_enable_iie(ap, !want_edma); 1649000b344fSMark Lord 1650000b344fSMark Lord if (IS_SOC(hpriv)) { 1651000b344fSMark Lord if (want_ncq) 1652000b344fSMark Lord mv_soc_led_blink_enable(ap); 1653000b344fSMark Lord else 1654000b344fSMark Lord mv_soc_led_blink_disable(ap); 1655000b344fSMark Lord } 1656c6fd2807SJeff Garzik } 1657c6fd2807SJeff Garzik 165872109168SMark Lord if (want_ncq) { 165972109168SMark Lord cfg |= EDMA_CFG_NCQ; 166072109168SMark Lord pp->pp_flags |= MV_PP_FLAG_NCQ_EN; 166100b81235SMark Lord } 166272109168SMark Lord 1663cae5a29dSMark Lord writelfl(cfg, port_mmio + EDMA_CFG); 1664c6fd2807SJeff Garzik } 1665c6fd2807SJeff Garzik 1666da2fa9baSMark Lord static void mv_port_free_dma_mem(struct ata_port *ap) 1667da2fa9baSMark Lord { 1668da2fa9baSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1669da2fa9baSMark Lord struct mv_port_priv *pp = ap->private_data; 1670eb73d558SMark Lord int tag; 1671da2fa9baSMark Lord 1672da2fa9baSMark Lord if (pp->crqb) { 1673da2fa9baSMark Lord dma_pool_free(hpriv->crqb_pool, pp->crqb, pp->crqb_dma); 1674da2fa9baSMark Lord pp->crqb = NULL; 1675da2fa9baSMark Lord } 1676da2fa9baSMark Lord if (pp->crpb) { 1677da2fa9baSMark Lord dma_pool_free(hpriv->crpb_pool, pp->crpb, pp->crpb_dma); 1678da2fa9baSMark Lord pp->crpb = NULL; 1679da2fa9baSMark Lord } 1680eb73d558SMark Lord /* 1681eb73d558SMark Lord * For GEN_I, there's no NCQ, so we have only a single sg_tbl. 1682eb73d558SMark Lord * For later hardware, we have one unique sg_tbl per NCQ tag. 1683eb73d558SMark Lord */ 1684eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1685eb73d558SMark Lord if (pp->sg_tbl[tag]) { 1686eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) 1687eb73d558SMark Lord dma_pool_free(hpriv->sg_tbl_pool, 1688eb73d558SMark Lord pp->sg_tbl[tag], 1689eb73d558SMark Lord pp->sg_tbl_dma[tag]); 1690eb73d558SMark Lord pp->sg_tbl[tag] = NULL; 1691eb73d558SMark Lord } 1692da2fa9baSMark Lord } 1693da2fa9baSMark Lord } 1694da2fa9baSMark Lord 1695c6fd2807SJeff Garzik /** 1696c6fd2807SJeff Garzik * mv_port_start - Port specific init/start routine. 1697c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1698c6fd2807SJeff Garzik * 1699c6fd2807SJeff Garzik * Allocate and point to DMA memory, init port private memory, 1700c6fd2807SJeff Garzik * zero indices. 1701c6fd2807SJeff Garzik * 1702c6fd2807SJeff Garzik * LOCKING: 1703c6fd2807SJeff Garzik * Inherited from caller. 1704c6fd2807SJeff Garzik */ 1705c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap) 1706c6fd2807SJeff Garzik { 1707cca3974eSJeff Garzik struct device *dev = ap->host->dev; 1708cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1709c6fd2807SJeff Garzik struct mv_port_priv *pp; 1710933cb8e5SMark Lord unsigned long flags; 1711dde20207SJames Bottomley int tag; 1712c6fd2807SJeff Garzik 171324dc5f33STejun Heo pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 1714c6fd2807SJeff Garzik if (!pp) 171524dc5f33STejun Heo return -ENOMEM; 1716da2fa9baSMark Lord ap->private_data = pp; 1717c6fd2807SJeff Garzik 1718da2fa9baSMark Lord pp->crqb = dma_pool_alloc(hpriv->crqb_pool, GFP_KERNEL, &pp->crqb_dma); 1719da2fa9baSMark Lord if (!pp->crqb) 1720da2fa9baSMark Lord return -ENOMEM; 1721da2fa9baSMark Lord memset(pp->crqb, 0, MV_CRQB_Q_SZ); 1722c6fd2807SJeff Garzik 1723da2fa9baSMark Lord pp->crpb = dma_pool_alloc(hpriv->crpb_pool, GFP_KERNEL, &pp->crpb_dma); 1724da2fa9baSMark Lord if (!pp->crpb) 1725da2fa9baSMark Lord goto out_port_free_dma_mem; 1726da2fa9baSMark Lord memset(pp->crpb, 0, MV_CRPB_Q_SZ); 1727c6fd2807SJeff Garzik 17283bd0a70eSMark Lord /* 6041/6081 Rev. "C0" (and newer) are okay with async notify */ 17293bd0a70eSMark Lord if (hpriv->hp_flags & MV_HP_ERRATA_60X1C0) 17303bd0a70eSMark Lord ap->flags |= ATA_FLAG_AN; 1731eb73d558SMark Lord /* 1732eb73d558SMark Lord * For GEN_I, there's no NCQ, so we only allocate a single sg_tbl. 1733eb73d558SMark Lord * For later hardware, we need one unique sg_tbl per NCQ tag. 1734eb73d558SMark Lord */ 1735eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1736eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) { 1737eb73d558SMark Lord pp->sg_tbl[tag] = dma_pool_alloc(hpriv->sg_tbl_pool, 1738eb73d558SMark Lord GFP_KERNEL, &pp->sg_tbl_dma[tag]); 1739eb73d558SMark Lord if (!pp->sg_tbl[tag]) 1740da2fa9baSMark Lord goto out_port_free_dma_mem; 1741eb73d558SMark Lord } else { 1742eb73d558SMark Lord pp->sg_tbl[tag] = pp->sg_tbl[0]; 1743eb73d558SMark Lord pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0]; 1744eb73d558SMark Lord } 1745eb73d558SMark Lord } 1746933cb8e5SMark Lord 1747933cb8e5SMark Lord spin_lock_irqsave(ap->lock, flags); 174808da1759SMark Lord mv_save_cached_regs(ap); 174966e57a2cSMark Lord mv_edma_cfg(ap, 0, 0); 1750933cb8e5SMark Lord spin_unlock_irqrestore(ap->lock, flags); 1751933cb8e5SMark Lord 1752c6fd2807SJeff Garzik return 0; 1753da2fa9baSMark Lord 1754da2fa9baSMark Lord out_port_free_dma_mem: 1755da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1756da2fa9baSMark Lord return -ENOMEM; 1757c6fd2807SJeff Garzik } 1758c6fd2807SJeff Garzik 1759c6fd2807SJeff Garzik /** 1760c6fd2807SJeff Garzik * mv_port_stop - Port specific cleanup/stop routine. 1761c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1762c6fd2807SJeff Garzik * 1763c6fd2807SJeff Garzik * Stop DMA, cleanup port memory. 1764c6fd2807SJeff Garzik * 1765c6fd2807SJeff Garzik * LOCKING: 1766cca3974eSJeff Garzik * This routine uses the host lock to protect the DMA stop. 1767c6fd2807SJeff Garzik */ 1768c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap) 1769c6fd2807SJeff Garzik { 1770933cb8e5SMark Lord unsigned long flags; 1771933cb8e5SMark Lord 1772933cb8e5SMark Lord spin_lock_irqsave(ap->lock, flags); 1773e12bef50SMark Lord mv_stop_edma(ap); 177488e675e1SMark Lord mv_enable_port_irqs(ap, 0); 1775933cb8e5SMark Lord spin_unlock_irqrestore(ap->lock, flags); 1776da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1777c6fd2807SJeff Garzik } 1778c6fd2807SJeff Garzik 1779c6fd2807SJeff Garzik /** 1780c6fd2807SJeff Garzik * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries 1781c6fd2807SJeff Garzik * @qc: queued command whose SG list to source from 1782c6fd2807SJeff Garzik * 1783c6fd2807SJeff Garzik * Populate the SG list and mark the last entry. 1784c6fd2807SJeff Garzik * 1785c6fd2807SJeff Garzik * LOCKING: 1786c6fd2807SJeff Garzik * Inherited from caller. 1787c6fd2807SJeff Garzik */ 17886c08772eSJeff Garzik static void mv_fill_sg(struct ata_queued_cmd *qc) 1789c6fd2807SJeff Garzik { 1790c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 1791c6fd2807SJeff Garzik struct scatterlist *sg; 17923be6cbd7SJeff Garzik struct mv_sg *mv_sg, *last_sg = NULL; 1793ff2aeb1eSTejun Heo unsigned int si; 1794c6fd2807SJeff Garzik 1795eb73d558SMark Lord mv_sg = pp->sg_tbl[qc->tag]; 1796ff2aeb1eSTejun Heo for_each_sg(qc->sg, sg, qc->n_elem, si) { 1797d88184fbSJeff Garzik dma_addr_t addr = sg_dma_address(sg); 1798d88184fbSJeff Garzik u32 sg_len = sg_dma_len(sg); 1799c6fd2807SJeff Garzik 18004007b493SOlof Johansson while (sg_len) { 18014007b493SOlof Johansson u32 offset = addr & 0xffff; 18024007b493SOlof Johansson u32 len = sg_len; 18034007b493SOlof Johansson 180432cd11a6SMark Lord if (offset + len > 0x10000) 18054007b493SOlof Johansson len = 0x10000 - offset; 18064007b493SOlof Johansson 1807d88184fbSJeff Garzik mv_sg->addr = cpu_to_le32(addr & 0xffffffff); 1808d88184fbSJeff Garzik mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16); 18096c08772eSJeff Garzik mv_sg->flags_size = cpu_to_le32(len & 0xffff); 181032cd11a6SMark Lord mv_sg->reserved = 0; 1811c6fd2807SJeff Garzik 18124007b493SOlof Johansson sg_len -= len; 18134007b493SOlof Johansson addr += len; 18144007b493SOlof Johansson 18153be6cbd7SJeff Garzik last_sg = mv_sg; 1816d88184fbSJeff Garzik mv_sg++; 1817c6fd2807SJeff Garzik } 18184007b493SOlof Johansson } 18193be6cbd7SJeff Garzik 18203be6cbd7SJeff Garzik if (likely(last_sg)) 18213be6cbd7SJeff Garzik last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 182232cd11a6SMark Lord mb(); /* ensure data structure is visible to the chipset */ 1823c6fd2807SJeff Garzik } 1824c6fd2807SJeff Garzik 18255796d1c4SJeff Garzik static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1826c6fd2807SJeff Garzik { 1827c6fd2807SJeff Garzik u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 1828c6fd2807SJeff Garzik (last ? CRQB_CMD_LAST : 0); 1829c6fd2807SJeff Garzik *cmdw = cpu_to_le16(tmp); 1830c6fd2807SJeff Garzik } 1831c6fd2807SJeff Garzik 1832c6fd2807SJeff Garzik /** 1833da14265eSMark Lord * mv_sff_irq_clear - Clear hardware interrupt after DMA. 1834da14265eSMark Lord * @ap: Port associated with this ATA transaction. 1835da14265eSMark Lord * 1836da14265eSMark Lord * We need this only for ATAPI bmdma transactions, 1837da14265eSMark Lord * as otherwise we experience spurious interrupts 1838da14265eSMark Lord * after libata-sff handles the bmdma interrupts. 1839da14265eSMark Lord */ 1840da14265eSMark Lord static void mv_sff_irq_clear(struct ata_port *ap) 1841da14265eSMark Lord { 1842da14265eSMark Lord mv_clear_and_enable_port_irqs(ap, mv_ap_base(ap), ERR_IRQ); 1843da14265eSMark Lord } 1844da14265eSMark Lord 1845da14265eSMark Lord /** 1846da14265eSMark Lord * mv_check_atapi_dma - Filter ATAPI cmds which are unsuitable for DMA. 1847da14265eSMark Lord * @qc: queued command to check for chipset/DMA compatibility. 1848da14265eSMark Lord * 1849da14265eSMark Lord * The bmdma engines cannot handle speculative data sizes 1850da14265eSMark Lord * (bytecount under/over flow). So only allow DMA for 1851da14265eSMark Lord * data transfer commands with known data sizes. 1852da14265eSMark Lord * 1853da14265eSMark Lord * LOCKING: 1854da14265eSMark Lord * Inherited from caller. 1855da14265eSMark Lord */ 1856da14265eSMark Lord static int mv_check_atapi_dma(struct ata_queued_cmd *qc) 1857da14265eSMark Lord { 1858da14265eSMark Lord struct scsi_cmnd *scmd = qc->scsicmd; 1859da14265eSMark Lord 1860da14265eSMark Lord if (scmd) { 1861da14265eSMark Lord switch (scmd->cmnd[0]) { 1862da14265eSMark Lord case READ_6: 1863da14265eSMark Lord case READ_10: 1864da14265eSMark Lord case READ_12: 1865da14265eSMark Lord case WRITE_6: 1866da14265eSMark Lord case WRITE_10: 1867da14265eSMark Lord case WRITE_12: 1868da14265eSMark Lord case GPCMD_READ_CD: 1869da14265eSMark Lord case GPCMD_SEND_DVD_STRUCTURE: 1870da14265eSMark Lord case GPCMD_SEND_CUE_SHEET: 1871da14265eSMark Lord return 0; /* DMA is safe */ 1872da14265eSMark Lord } 1873da14265eSMark Lord } 1874da14265eSMark Lord return -EOPNOTSUPP; /* use PIO instead */ 1875da14265eSMark Lord } 1876da14265eSMark Lord 1877da14265eSMark Lord /** 1878da14265eSMark Lord * mv_bmdma_setup - Set up BMDMA transaction 1879da14265eSMark Lord * @qc: queued command to prepare DMA for. 1880da14265eSMark Lord * 1881da14265eSMark Lord * LOCKING: 1882da14265eSMark Lord * Inherited from caller. 1883da14265eSMark Lord */ 1884da14265eSMark Lord static void mv_bmdma_setup(struct ata_queued_cmd *qc) 1885da14265eSMark Lord { 1886da14265eSMark Lord struct ata_port *ap = qc->ap; 1887da14265eSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 1888da14265eSMark Lord struct mv_port_priv *pp = ap->private_data; 1889da14265eSMark Lord 1890da14265eSMark Lord mv_fill_sg(qc); 1891da14265eSMark Lord 1892da14265eSMark Lord /* clear all DMA cmd bits */ 1893cae5a29dSMark Lord writel(0, port_mmio + BMDMA_CMD); 1894da14265eSMark Lord 1895da14265eSMark Lord /* load PRD table addr. */ 1896da14265eSMark Lord writel((pp->sg_tbl_dma[qc->tag] >> 16) >> 16, 1897cae5a29dSMark Lord port_mmio + BMDMA_PRD_HIGH); 1898da14265eSMark Lord writelfl(pp->sg_tbl_dma[qc->tag], 1899cae5a29dSMark Lord port_mmio + BMDMA_PRD_LOW); 1900da14265eSMark Lord 1901da14265eSMark Lord /* issue r/w command */ 1902da14265eSMark Lord ap->ops->sff_exec_command(ap, &qc->tf); 1903da14265eSMark Lord } 1904da14265eSMark Lord 1905da14265eSMark Lord /** 1906da14265eSMark Lord * mv_bmdma_start - Start a BMDMA transaction 1907da14265eSMark Lord * @qc: queued command to start DMA on. 1908da14265eSMark Lord * 1909da14265eSMark Lord * LOCKING: 1910da14265eSMark Lord * Inherited from caller. 1911da14265eSMark Lord */ 1912da14265eSMark Lord static void mv_bmdma_start(struct ata_queued_cmd *qc) 1913da14265eSMark Lord { 1914da14265eSMark Lord struct ata_port *ap = qc->ap; 1915da14265eSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 1916da14265eSMark Lord unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); 1917da14265eSMark Lord u32 cmd = (rw ? 0 : ATA_DMA_WR) | ATA_DMA_START; 1918da14265eSMark Lord 1919da14265eSMark Lord /* start host DMA transaction */ 1920cae5a29dSMark Lord writelfl(cmd, port_mmio + BMDMA_CMD); 1921da14265eSMark Lord } 1922da14265eSMark Lord 1923da14265eSMark Lord /** 1924da14265eSMark Lord * mv_bmdma_stop - Stop BMDMA transfer 1925da14265eSMark Lord * @qc: queued command to stop DMA on. 1926da14265eSMark Lord * 1927da14265eSMark Lord * Clears the ATA_DMA_START flag in the bmdma control register 1928da14265eSMark Lord * 1929da14265eSMark Lord * LOCKING: 1930da14265eSMark Lord * Inherited from caller. 1931da14265eSMark Lord */ 193244b73380SMark Lord static void mv_bmdma_stop_ap(struct ata_port *ap) 1933da14265eSMark Lord { 1934da14265eSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 1935da14265eSMark Lord u32 cmd; 1936da14265eSMark Lord 1937da14265eSMark Lord /* clear start/stop bit */ 1938cae5a29dSMark Lord cmd = readl(port_mmio + BMDMA_CMD); 193944b73380SMark Lord if (cmd & ATA_DMA_START) { 1940da14265eSMark Lord cmd &= ~ATA_DMA_START; 1941cae5a29dSMark Lord writelfl(cmd, port_mmio + BMDMA_CMD); 1942da14265eSMark Lord 1943da14265eSMark Lord /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 1944da14265eSMark Lord ata_sff_dma_pause(ap); 1945da14265eSMark Lord } 194644b73380SMark Lord } 194744b73380SMark Lord 194844b73380SMark Lord static void mv_bmdma_stop(struct ata_queued_cmd *qc) 194944b73380SMark Lord { 195044b73380SMark Lord mv_bmdma_stop_ap(qc->ap); 195144b73380SMark Lord } 1952da14265eSMark Lord 1953da14265eSMark Lord /** 1954da14265eSMark Lord * mv_bmdma_status - Read BMDMA status 1955da14265eSMark Lord * @ap: port for which to retrieve DMA status. 1956da14265eSMark Lord * 1957da14265eSMark Lord * Read and return equivalent of the sff BMDMA status register. 1958da14265eSMark Lord * 1959da14265eSMark Lord * LOCKING: 1960da14265eSMark Lord * Inherited from caller. 1961da14265eSMark Lord */ 1962da14265eSMark Lord static u8 mv_bmdma_status(struct ata_port *ap) 1963da14265eSMark Lord { 1964da14265eSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 1965da14265eSMark Lord u32 reg, status; 1966da14265eSMark Lord 1967da14265eSMark Lord /* 1968da14265eSMark Lord * Other bits are valid only if ATA_DMA_ACTIVE==0, 1969da14265eSMark Lord * and the ATA_DMA_INTR bit doesn't exist. 1970da14265eSMark Lord */ 1971cae5a29dSMark Lord reg = readl(port_mmio + BMDMA_STATUS); 1972da14265eSMark Lord if (reg & ATA_DMA_ACTIVE) 1973da14265eSMark Lord status = ATA_DMA_ACTIVE; 197444b73380SMark Lord else if (reg & ATA_DMA_ERR) 1975da14265eSMark Lord status = (reg & ATA_DMA_ERR) | ATA_DMA_INTR; 197644b73380SMark Lord else { 197744b73380SMark Lord /* 197844b73380SMark Lord * Just because DMA_ACTIVE is 0 (DMA completed), 197944b73380SMark Lord * this does _not_ mean the device is "done". 198044b73380SMark Lord * So we should not yet be signalling ATA_DMA_INTR 198144b73380SMark Lord * in some cases. Eg. DSM/TRIM, and perhaps others. 198244b73380SMark Lord */ 198344b73380SMark Lord mv_bmdma_stop_ap(ap); 198444b73380SMark Lord if (ioread8(ap->ioaddr.altstatus_addr) & ATA_BUSY) 198544b73380SMark Lord status = 0; 198644b73380SMark Lord else 198744b73380SMark Lord status = ATA_DMA_INTR; 198844b73380SMark Lord } 1989da14265eSMark Lord return status; 1990da14265eSMark Lord } 1991da14265eSMark Lord 1992299b3f8dSMark Lord static void mv_rw_multi_errata_sata24(struct ata_queued_cmd *qc) 1993299b3f8dSMark Lord { 1994299b3f8dSMark Lord struct ata_taskfile *tf = &qc->tf; 1995299b3f8dSMark Lord /* 1996299b3f8dSMark Lord * Workaround for 88SX60x1 FEr SATA#24. 1997299b3f8dSMark Lord * 1998299b3f8dSMark Lord * Chip may corrupt WRITEs if multi_count >= 4kB. 1999299b3f8dSMark Lord * Note that READs are unaffected. 2000299b3f8dSMark Lord * 2001299b3f8dSMark Lord * It's not clear if this errata really means "4K bytes", 2002299b3f8dSMark Lord * or if it always happens for multi_count > 7 2003299b3f8dSMark Lord * regardless of device sector_size. 2004299b3f8dSMark Lord * 2005299b3f8dSMark Lord * So, for safety, any write with multi_count > 7 2006299b3f8dSMark Lord * gets converted here into a regular PIO write instead: 2007299b3f8dSMark Lord */ 2008299b3f8dSMark Lord if ((tf->flags & ATA_TFLAG_WRITE) && is_multi_taskfile(tf)) { 2009299b3f8dSMark Lord if (qc->dev->multi_count > 7) { 2010299b3f8dSMark Lord switch (tf->command) { 2011299b3f8dSMark Lord case ATA_CMD_WRITE_MULTI: 2012299b3f8dSMark Lord tf->command = ATA_CMD_PIO_WRITE; 2013299b3f8dSMark Lord break; 2014299b3f8dSMark Lord case ATA_CMD_WRITE_MULTI_FUA_EXT: 2015299b3f8dSMark Lord tf->flags &= ~ATA_TFLAG_FUA; /* ugh */ 2016299b3f8dSMark Lord /* fall through */ 2017299b3f8dSMark Lord case ATA_CMD_WRITE_MULTI_EXT: 2018299b3f8dSMark Lord tf->command = ATA_CMD_PIO_WRITE_EXT; 2019299b3f8dSMark Lord break; 2020299b3f8dSMark Lord } 2021299b3f8dSMark Lord } 2022299b3f8dSMark Lord } 2023299b3f8dSMark Lord } 2024299b3f8dSMark Lord 2025da14265eSMark Lord /** 2026c6fd2807SJeff Garzik * mv_qc_prep - Host specific command preparation. 2027c6fd2807SJeff Garzik * @qc: queued command to prepare 2028c6fd2807SJeff Garzik * 2029c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 2030c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 2031c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 2032c6fd2807SJeff Garzik * the SG load routine. 2033c6fd2807SJeff Garzik * 2034c6fd2807SJeff Garzik * LOCKING: 2035c6fd2807SJeff Garzik * Inherited from caller. 2036c6fd2807SJeff Garzik */ 2037c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc) 2038c6fd2807SJeff Garzik { 2039c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 2040c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 2041c6fd2807SJeff Garzik __le16 *cw; 20428d2b450dSMark Lord struct ata_taskfile *tf = &qc->tf; 2043c6fd2807SJeff Garzik u16 flags = 0; 2044c6fd2807SJeff Garzik unsigned in_index; 2045c6fd2807SJeff Garzik 2046299b3f8dSMark Lord switch (tf->protocol) { 2047299b3f8dSMark Lord case ATA_PROT_DMA: 204844b73380SMark Lord if (tf->command == ATA_CMD_DSM) 204944b73380SMark Lord return; 205044b73380SMark Lord /* fall-thru */ 2051299b3f8dSMark Lord case ATA_PROT_NCQ: 2052299b3f8dSMark Lord break; /* continue below */ 2053299b3f8dSMark Lord case ATA_PROT_PIO: 2054299b3f8dSMark Lord mv_rw_multi_errata_sata24(qc); 2055c6fd2807SJeff Garzik return; 2056299b3f8dSMark Lord default: 2057299b3f8dSMark Lord return; 2058299b3f8dSMark Lord } 2059c6fd2807SJeff Garzik 2060c6fd2807SJeff Garzik /* Fill in command request block 2061c6fd2807SJeff Garzik */ 20628d2b450dSMark Lord if (!(tf->flags & ATA_TFLAG_WRITE)) 2063c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 2064c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 2065c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 2066e49856d8SMark Lord flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT; 2067c6fd2807SJeff Garzik 2068bdd4dddeSJeff Garzik /* get current queue index from software */ 2069fcfb1f77SMark Lord in_index = pp->req_idx; 2070c6fd2807SJeff Garzik 2071c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr = 2072eb73d558SMark Lord cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 2073c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr_hi = 2074eb73d558SMark Lord cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 2075c6fd2807SJeff Garzik pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags); 2076c6fd2807SJeff Garzik 2077c6fd2807SJeff Garzik cw = &pp->crqb[in_index].ata_cmd[0]; 2078c6fd2807SJeff Garzik 207925985edcSLucas De Marchi /* Sadly, the CRQB cannot accommodate all registers--there are 2080c6fd2807SJeff Garzik * only 11 bytes...so we must pick and choose required 2081c6fd2807SJeff Garzik * registers based on the command. So, we drop feature and 2082c6fd2807SJeff Garzik * hob_feature for [RW] DMA commands, but they are needed for 2083cd12e1f7SMark Lord * NCQ. NCQ will drop hob_nsect, which is not needed there 2084cd12e1f7SMark Lord * (nsect is used only for the tag; feat/hob_feat hold true nsect). 2085c6fd2807SJeff Garzik */ 2086c6fd2807SJeff Garzik switch (tf->command) { 2087c6fd2807SJeff Garzik case ATA_CMD_READ: 2088c6fd2807SJeff Garzik case ATA_CMD_READ_EXT: 2089c6fd2807SJeff Garzik case ATA_CMD_WRITE: 2090c6fd2807SJeff Garzik case ATA_CMD_WRITE_EXT: 2091c6fd2807SJeff Garzik case ATA_CMD_WRITE_FUA_EXT: 2092c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0); 2093c6fd2807SJeff Garzik break; 2094c6fd2807SJeff Garzik case ATA_CMD_FPDMA_READ: 2095c6fd2807SJeff Garzik case ATA_CMD_FPDMA_WRITE: 2096c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); 2097c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); 2098c6fd2807SJeff Garzik break; 2099c6fd2807SJeff Garzik default: 2100c6fd2807SJeff Garzik /* The only other commands EDMA supports in non-queued and 2101c6fd2807SJeff Garzik * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none 2102c6fd2807SJeff Garzik * of which are defined/used by Linux. If we get here, this 2103c6fd2807SJeff Garzik * driver needs work. 2104c6fd2807SJeff Garzik * 2105c6fd2807SJeff Garzik * FIXME: modify libata to give qc_prep a return value and 2106c6fd2807SJeff Garzik * return error here. 2107c6fd2807SJeff Garzik */ 2108c6fd2807SJeff Garzik BUG_ON(tf->command); 2109c6fd2807SJeff Garzik break; 2110c6fd2807SJeff Garzik } 2111c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0); 2112c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0); 2113c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0); 2114c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0); 2115c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0); 2116c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0); 2117c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0); 2118c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 2119c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 2120c6fd2807SJeff Garzik 2121c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 2122c6fd2807SJeff Garzik return; 2123c6fd2807SJeff Garzik mv_fill_sg(qc); 2124c6fd2807SJeff Garzik } 2125c6fd2807SJeff Garzik 2126c6fd2807SJeff Garzik /** 2127c6fd2807SJeff Garzik * mv_qc_prep_iie - Host specific command preparation. 2128c6fd2807SJeff Garzik * @qc: queued command to prepare 2129c6fd2807SJeff Garzik * 2130c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 2131c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 2132c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 2133c6fd2807SJeff Garzik * the SG load routine. 2134c6fd2807SJeff Garzik * 2135c6fd2807SJeff Garzik * LOCKING: 2136c6fd2807SJeff Garzik * Inherited from caller. 2137c6fd2807SJeff Garzik */ 2138c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc) 2139c6fd2807SJeff Garzik { 2140c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 2141c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 2142c6fd2807SJeff Garzik struct mv_crqb_iie *crqb; 21438d2b450dSMark Lord struct ata_taskfile *tf = &qc->tf; 2144c6fd2807SJeff Garzik unsigned in_index; 2145c6fd2807SJeff Garzik u32 flags = 0; 2146c6fd2807SJeff Garzik 21478d2b450dSMark Lord if ((tf->protocol != ATA_PROT_DMA) && 21488d2b450dSMark Lord (tf->protocol != ATA_PROT_NCQ)) 2149c6fd2807SJeff Garzik return; 215044b73380SMark Lord if (tf->command == ATA_CMD_DSM) 215144b73380SMark Lord return; /* use bmdma for this */ 2152c6fd2807SJeff Garzik 2153e12bef50SMark Lord /* Fill in Gen IIE command request block */ 21548d2b450dSMark Lord if (!(tf->flags & ATA_TFLAG_WRITE)) 2155c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 2156c6fd2807SJeff Garzik 2157c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 2158c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 21598c0aeb4aSMark Lord flags |= qc->tag << CRQB_HOSTQ_SHIFT; 2160e49856d8SMark Lord flags |= (qc->dev->link->pmp & 0xf) << CRQB_PMP_SHIFT; 2161c6fd2807SJeff Garzik 2162bdd4dddeSJeff Garzik /* get current queue index from software */ 2163fcfb1f77SMark Lord in_index = pp->req_idx; 2164c6fd2807SJeff Garzik 2165c6fd2807SJeff Garzik crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 2166eb73d558SMark Lord crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 2167eb73d558SMark Lord crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 2168c6fd2807SJeff Garzik crqb->flags = cpu_to_le32(flags); 2169c6fd2807SJeff Garzik 2170c6fd2807SJeff Garzik crqb->ata_cmd[0] = cpu_to_le32( 2171c6fd2807SJeff Garzik (tf->command << 16) | 2172c6fd2807SJeff Garzik (tf->feature << 24) 2173c6fd2807SJeff Garzik ); 2174c6fd2807SJeff Garzik crqb->ata_cmd[1] = cpu_to_le32( 2175c6fd2807SJeff Garzik (tf->lbal << 0) | 2176c6fd2807SJeff Garzik (tf->lbam << 8) | 2177c6fd2807SJeff Garzik (tf->lbah << 16) | 2178c6fd2807SJeff Garzik (tf->device << 24) 2179c6fd2807SJeff Garzik ); 2180c6fd2807SJeff Garzik crqb->ata_cmd[2] = cpu_to_le32( 2181c6fd2807SJeff Garzik (tf->hob_lbal << 0) | 2182c6fd2807SJeff Garzik (tf->hob_lbam << 8) | 2183c6fd2807SJeff Garzik (tf->hob_lbah << 16) | 2184c6fd2807SJeff Garzik (tf->hob_feature << 24) 2185c6fd2807SJeff Garzik ); 2186c6fd2807SJeff Garzik crqb->ata_cmd[3] = cpu_to_le32( 2187c6fd2807SJeff Garzik (tf->nsect << 0) | 2188c6fd2807SJeff Garzik (tf->hob_nsect << 8) 2189c6fd2807SJeff Garzik ); 2190c6fd2807SJeff Garzik 2191c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 2192c6fd2807SJeff Garzik return; 2193c6fd2807SJeff Garzik mv_fill_sg(qc); 2194c6fd2807SJeff Garzik } 2195c6fd2807SJeff Garzik 2196c6fd2807SJeff Garzik /** 2197d16ab3f6SMark Lord * mv_sff_check_status - fetch device status, if valid 2198d16ab3f6SMark Lord * @ap: ATA port to fetch status from 2199d16ab3f6SMark Lord * 2200d16ab3f6SMark Lord * When using command issue via mv_qc_issue_fis(), 2201d16ab3f6SMark Lord * the initial ATA_BUSY state does not show up in the 2202d16ab3f6SMark Lord * ATA status (shadow) register. This can confuse libata! 2203d16ab3f6SMark Lord * 2204d16ab3f6SMark Lord * So we have a hook here to fake ATA_BUSY for that situation, 2205d16ab3f6SMark Lord * until the first time a BUSY, DRQ, or ERR bit is seen. 2206d16ab3f6SMark Lord * 2207d16ab3f6SMark Lord * The rest of the time, it simply returns the ATA status register. 2208d16ab3f6SMark Lord */ 2209d16ab3f6SMark Lord static u8 mv_sff_check_status(struct ata_port *ap) 2210d16ab3f6SMark Lord { 2211d16ab3f6SMark Lord u8 stat = ioread8(ap->ioaddr.status_addr); 2212d16ab3f6SMark Lord struct mv_port_priv *pp = ap->private_data; 2213d16ab3f6SMark Lord 2214d16ab3f6SMark Lord if (pp->pp_flags & MV_PP_FLAG_FAKE_ATA_BUSY) { 2215d16ab3f6SMark Lord if (stat & (ATA_BUSY | ATA_DRQ | ATA_ERR)) 2216d16ab3f6SMark Lord pp->pp_flags &= ~MV_PP_FLAG_FAKE_ATA_BUSY; 2217d16ab3f6SMark Lord else 2218d16ab3f6SMark Lord stat = ATA_BUSY; 2219d16ab3f6SMark Lord } 2220d16ab3f6SMark Lord return stat; 2221d16ab3f6SMark Lord } 2222d16ab3f6SMark Lord 2223d16ab3f6SMark Lord /** 222470f8b79cSMark Lord * mv_send_fis - Send a FIS, using the "Vendor-Unique FIS" register 222570f8b79cSMark Lord * @fis: fis to be sent 222670f8b79cSMark Lord * @nwords: number of 32-bit words in the fis 222770f8b79cSMark Lord */ 222870f8b79cSMark Lord static unsigned int mv_send_fis(struct ata_port *ap, u32 *fis, int nwords) 222970f8b79cSMark Lord { 223070f8b79cSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 223170f8b79cSMark Lord u32 ifctl, old_ifctl, ifstat; 223270f8b79cSMark Lord int i, timeout = 200, final_word = nwords - 1; 223370f8b79cSMark Lord 223470f8b79cSMark Lord /* Initiate FIS transmission mode */ 2235cae5a29dSMark Lord old_ifctl = readl(port_mmio + SATA_IFCTL); 223670f8b79cSMark Lord ifctl = 0x100 | (old_ifctl & 0xf); 2237cae5a29dSMark Lord writelfl(ifctl, port_mmio + SATA_IFCTL); 223870f8b79cSMark Lord 223970f8b79cSMark Lord /* Send all words of the FIS except for the final word */ 224070f8b79cSMark Lord for (i = 0; i < final_word; ++i) 2241cae5a29dSMark Lord writel(fis[i], port_mmio + VENDOR_UNIQUE_FIS); 224270f8b79cSMark Lord 224370f8b79cSMark Lord /* Flag end-of-transmission, and then send the final word */ 2244cae5a29dSMark Lord writelfl(ifctl | 0x200, port_mmio + SATA_IFCTL); 2245cae5a29dSMark Lord writelfl(fis[final_word], port_mmio + VENDOR_UNIQUE_FIS); 224670f8b79cSMark Lord 224770f8b79cSMark Lord /* 224870f8b79cSMark Lord * Wait for FIS transmission to complete. 224970f8b79cSMark Lord * This typically takes just a single iteration. 225070f8b79cSMark Lord */ 225170f8b79cSMark Lord do { 2252cae5a29dSMark Lord ifstat = readl(port_mmio + SATA_IFSTAT); 225370f8b79cSMark Lord } while (!(ifstat & 0x1000) && --timeout); 225470f8b79cSMark Lord 225570f8b79cSMark Lord /* Restore original port configuration */ 2256cae5a29dSMark Lord writelfl(old_ifctl, port_mmio + SATA_IFCTL); 225770f8b79cSMark Lord 225870f8b79cSMark Lord /* See if it worked */ 225970f8b79cSMark Lord if ((ifstat & 0x3000) != 0x1000) { 2260a9a79dfeSJoe Perches ata_port_warn(ap, "%s transmission error, ifstat=%08x\n", 226170f8b79cSMark Lord __func__, ifstat); 226270f8b79cSMark Lord return AC_ERR_OTHER; 226370f8b79cSMark Lord } 226470f8b79cSMark Lord return 0; 226570f8b79cSMark Lord } 226670f8b79cSMark Lord 226770f8b79cSMark Lord /** 226870f8b79cSMark Lord * mv_qc_issue_fis - Issue a command directly as a FIS 226970f8b79cSMark Lord * @qc: queued command to start 227070f8b79cSMark Lord * 227170f8b79cSMark Lord * Note that the ATA shadow registers are not updated 227270f8b79cSMark Lord * after command issue, so the device will appear "READY" 227370f8b79cSMark Lord * if polled, even while it is BUSY processing the command. 227470f8b79cSMark Lord * 227570f8b79cSMark Lord * So we use a status hook to fake ATA_BUSY until the drive changes state. 227670f8b79cSMark Lord * 227770f8b79cSMark Lord * Note: we don't get updated shadow regs on *completion* 227870f8b79cSMark Lord * of non-data commands. So avoid sending them via this function, 227970f8b79cSMark Lord * as they will appear to have completed immediately. 228070f8b79cSMark Lord * 228170f8b79cSMark Lord * GEN_IIE has special registers that we could get the result tf from, 228270f8b79cSMark Lord * but earlier chipsets do not. For now, we ignore those registers. 228370f8b79cSMark Lord */ 228470f8b79cSMark Lord static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc) 228570f8b79cSMark Lord { 228670f8b79cSMark Lord struct ata_port *ap = qc->ap; 228770f8b79cSMark Lord struct mv_port_priv *pp = ap->private_data; 228870f8b79cSMark Lord struct ata_link *link = qc->dev->link; 228970f8b79cSMark Lord u32 fis[5]; 229070f8b79cSMark Lord int err = 0; 229170f8b79cSMark Lord 229270f8b79cSMark Lord ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis); 22934c4a90fdSThiago Farina err = mv_send_fis(ap, fis, ARRAY_SIZE(fis)); 229470f8b79cSMark Lord if (err) 229570f8b79cSMark Lord return err; 229670f8b79cSMark Lord 229770f8b79cSMark Lord switch (qc->tf.protocol) { 229870f8b79cSMark Lord case ATAPI_PROT_PIO: 229970f8b79cSMark Lord pp->pp_flags |= MV_PP_FLAG_FAKE_ATA_BUSY; 230070f8b79cSMark Lord /* fall through */ 230170f8b79cSMark Lord case ATAPI_PROT_NODATA: 230270f8b79cSMark Lord ap->hsm_task_state = HSM_ST_FIRST; 230370f8b79cSMark Lord break; 230470f8b79cSMark Lord case ATA_PROT_PIO: 230570f8b79cSMark Lord pp->pp_flags |= MV_PP_FLAG_FAKE_ATA_BUSY; 230670f8b79cSMark Lord if (qc->tf.flags & ATA_TFLAG_WRITE) 230770f8b79cSMark Lord ap->hsm_task_state = HSM_ST_FIRST; 230870f8b79cSMark Lord else 230970f8b79cSMark Lord ap->hsm_task_state = HSM_ST; 231070f8b79cSMark Lord break; 231170f8b79cSMark Lord default: 231270f8b79cSMark Lord ap->hsm_task_state = HSM_ST_LAST; 231370f8b79cSMark Lord break; 231470f8b79cSMark Lord } 231570f8b79cSMark Lord 231670f8b79cSMark Lord if (qc->tf.flags & ATA_TFLAG_POLLING) 2317ea3c6450SGwendal Grignou ata_sff_queue_pio_task(link, 0); 231870f8b79cSMark Lord return 0; 231970f8b79cSMark Lord } 232070f8b79cSMark Lord 232170f8b79cSMark Lord /** 2322c6fd2807SJeff Garzik * mv_qc_issue - Initiate a command to the host 2323c6fd2807SJeff Garzik * @qc: queued command to start 2324c6fd2807SJeff Garzik * 2325c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 2326c6fd2807SJeff Garzik * if command is not DMA. Else, it sanity checks our local 2327c6fd2807SJeff Garzik * caches of the request producer/consumer indices then enables 2328c6fd2807SJeff Garzik * DMA and bumps the request producer index. 2329c6fd2807SJeff Garzik * 2330c6fd2807SJeff Garzik * LOCKING: 2331c6fd2807SJeff Garzik * Inherited from caller. 2332c6fd2807SJeff Garzik */ 2333c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 2334c6fd2807SJeff Garzik { 2335f48765ccSMark Lord static int limit_warnings = 10; 2336c5d3e45aSJeff Garzik struct ata_port *ap = qc->ap; 2337c5d3e45aSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2338c5d3e45aSJeff Garzik struct mv_port_priv *pp = ap->private_data; 2339bdd4dddeSJeff Garzik u32 in_index; 234042ed893dSMark Lord unsigned int port_irqs; 2341c6fd2807SJeff Garzik 2342d16ab3f6SMark Lord pp->pp_flags &= ~MV_PP_FLAG_FAKE_ATA_BUSY; /* paranoia */ 2343d16ab3f6SMark Lord 2344f48765ccSMark Lord switch (qc->tf.protocol) { 2345f48765ccSMark Lord case ATA_PROT_DMA: 234644b73380SMark Lord if (qc->tf.command == ATA_CMD_DSM) { 234744b73380SMark Lord if (!ap->ops->bmdma_setup) /* no bmdma on GEN_I */ 234844b73380SMark Lord return AC_ERR_OTHER; 234944b73380SMark Lord break; /* use bmdma for this */ 235044b73380SMark Lord } 235144b73380SMark Lord /* fall thru */ 2352f48765ccSMark Lord case ATA_PROT_NCQ: 2353f48765ccSMark Lord mv_start_edma(ap, port_mmio, pp, qc->tf.protocol); 2354f48765ccSMark Lord pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK; 2355f48765ccSMark Lord in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT; 2356f48765ccSMark Lord 2357f48765ccSMark Lord /* Write the request in pointer to kick the EDMA to life */ 2358f48765ccSMark Lord writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 2359cae5a29dSMark Lord port_mmio + EDMA_REQ_Q_IN_PTR); 2360f48765ccSMark Lord return 0; 2361f48765ccSMark Lord 2362f48765ccSMark Lord case ATA_PROT_PIO: 2363c6112bd8SMark Lord /* 2364c6112bd8SMark Lord * Errata SATA#16, SATA#24: warn if multiple DRQs expected. 2365c6112bd8SMark Lord * 2366c6112bd8SMark Lord * Someday, we might implement special polling workarounds 2367c6112bd8SMark Lord * for these, but it all seems rather unnecessary since we 2368c6112bd8SMark Lord * normally use only DMA for commands which transfer more 2369c6112bd8SMark Lord * than a single block of data. 2370c6112bd8SMark Lord * 2371c6112bd8SMark Lord * Much of the time, this could just work regardless. 2372c6112bd8SMark Lord * So for now, just log the incident, and allow the attempt. 2373c6112bd8SMark Lord */ 2374c7843e8fSMark Lord if (limit_warnings > 0 && (qc->nbytes / qc->sect_size) > 1) { 2375c6112bd8SMark Lord --limit_warnings; 2376a9a79dfeSJoe Perches ata_link_warn(qc->dev->link, DRV_NAME 2377c6112bd8SMark Lord ": attempting PIO w/multiple DRQ: " 2378c6112bd8SMark Lord "this may fail due to h/w errata\n"); 2379c6112bd8SMark Lord } 2380f48765ccSMark Lord /* drop through */ 238142ed893dSMark Lord case ATA_PROT_NODATA: 2382f48765ccSMark Lord case ATAPI_PROT_PIO: 238342ed893dSMark Lord case ATAPI_PROT_NODATA: 238442ed893dSMark Lord if (ap->flags & ATA_FLAG_PIO_POLLING) 238542ed893dSMark Lord qc->tf.flags |= ATA_TFLAG_POLLING; 238642ed893dSMark Lord break; 238742ed893dSMark Lord } 238842ed893dSMark Lord 238942ed893dSMark Lord if (qc->tf.flags & ATA_TFLAG_POLLING) 239042ed893dSMark Lord port_irqs = ERR_IRQ; /* mask device interrupt when polling */ 239142ed893dSMark Lord else 239242ed893dSMark Lord port_irqs = ERR_IRQ | DONE_IRQ; /* unmask all interrupts */ 239342ed893dSMark Lord 239417c5aab5SMark Lord /* 239517c5aab5SMark Lord * We're about to send a non-EDMA capable command to the 2396c6fd2807SJeff Garzik * port. Turn off EDMA so there won't be problems accessing 2397c6fd2807SJeff Garzik * shadow block, etc registers. 2398c6fd2807SJeff Garzik */ 2399b562468cSMark Lord mv_stop_edma(ap); 2400f48765ccSMark Lord mv_clear_and_enable_port_irqs(ap, mv_ap_base(ap), port_irqs); 2401e49856d8SMark Lord mv_pmp_select(ap, qc->dev->link->pmp); 240270f8b79cSMark Lord 240370f8b79cSMark Lord if (qc->tf.command == ATA_CMD_READ_LOG_EXT) { 240470f8b79cSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 240570f8b79cSMark Lord /* 240670f8b79cSMark Lord * Workaround for 88SX60x1 FEr SATA#25 (part 2). 240770f8b79cSMark Lord * 240870f8b79cSMark Lord * After any NCQ error, the READ_LOG_EXT command 240970f8b79cSMark Lord * from libata-eh *must* use mv_qc_issue_fis(). 241070f8b79cSMark Lord * Otherwise it might fail, due to chip errata. 241170f8b79cSMark Lord * 241270f8b79cSMark Lord * Rather than special-case it, we'll just *always* 241370f8b79cSMark Lord * use this method here for READ_LOG_EXT, making for 241470f8b79cSMark Lord * easier testing. 241570f8b79cSMark Lord */ 241670f8b79cSMark Lord if (IS_GEN_II(hpriv)) 241770f8b79cSMark Lord return mv_qc_issue_fis(qc); 241870f8b79cSMark Lord } 2419360ff783STejun Heo return ata_bmdma_qc_issue(qc); 2420c6fd2807SJeff Garzik } 2421c6fd2807SJeff Garzik 24228f767f8aSMark Lord static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap) 24238f767f8aSMark Lord { 24248f767f8aSMark Lord struct mv_port_priv *pp = ap->private_data; 24258f767f8aSMark Lord struct ata_queued_cmd *qc; 24268f767f8aSMark Lord 24278f767f8aSMark Lord if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) 24288f767f8aSMark Lord return NULL; 24298f767f8aSMark Lord qc = ata_qc_from_tag(ap, ap->link.active_tag); 24303e4ec344STejun Heo if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING)) 24318f767f8aSMark Lord return qc; 24323e4ec344STejun Heo return NULL; 24338f767f8aSMark Lord } 24348f767f8aSMark Lord 243529d187bbSMark Lord static void mv_pmp_error_handler(struct ata_port *ap) 243629d187bbSMark Lord { 243729d187bbSMark Lord unsigned int pmp, pmp_map; 243829d187bbSMark Lord struct mv_port_priv *pp = ap->private_data; 243929d187bbSMark Lord 244029d187bbSMark Lord if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH) { 244129d187bbSMark Lord /* 244229d187bbSMark Lord * Perform NCQ error analysis on failed PMPs 244329d187bbSMark Lord * before we freeze the port entirely. 244429d187bbSMark Lord * 244529d187bbSMark Lord * The failed PMPs are marked earlier by mv_pmp_eh_prep(). 244629d187bbSMark Lord */ 244729d187bbSMark Lord pmp_map = pp->delayed_eh_pmp_map; 244829d187bbSMark Lord pp->pp_flags &= ~MV_PP_FLAG_DELAYED_EH; 244929d187bbSMark Lord for (pmp = 0; pmp_map != 0; pmp++) { 245029d187bbSMark Lord unsigned int this_pmp = (1 << pmp); 245129d187bbSMark Lord if (pmp_map & this_pmp) { 245229d187bbSMark Lord struct ata_link *link = &ap->pmp_link[pmp]; 245329d187bbSMark Lord pmp_map &= ~this_pmp; 245429d187bbSMark Lord ata_eh_analyze_ncq_error(link); 245529d187bbSMark Lord } 245629d187bbSMark Lord } 245729d187bbSMark Lord ata_port_freeze(ap); 245829d187bbSMark Lord } 245929d187bbSMark Lord sata_pmp_error_handler(ap); 246029d187bbSMark Lord } 246129d187bbSMark Lord 24624c299ca3SMark Lord static unsigned int mv_get_err_pmp_map(struct ata_port *ap) 24634c299ca3SMark Lord { 24644c299ca3SMark Lord void __iomem *port_mmio = mv_ap_base(ap); 24654c299ca3SMark Lord 2466cae5a29dSMark Lord return readl(port_mmio + SATA_TESTCTL) >> 16; 24674c299ca3SMark Lord } 24684c299ca3SMark Lord 24694c299ca3SMark Lord static void mv_pmp_eh_prep(struct ata_port *ap, unsigned int pmp_map) 24704c299ca3SMark Lord { 24714c299ca3SMark Lord struct ata_eh_info *ehi; 24724c299ca3SMark Lord unsigned int pmp; 24734c299ca3SMark Lord 24744c299ca3SMark Lord /* 24754c299ca3SMark Lord * Initialize EH info for PMPs which saw device errors 24764c299ca3SMark Lord */ 24774c299ca3SMark Lord ehi = &ap->link.eh_info; 24784c299ca3SMark Lord for (pmp = 0; pmp_map != 0; pmp++) { 24794c299ca3SMark Lord unsigned int this_pmp = (1 << pmp); 24804c299ca3SMark Lord if (pmp_map & this_pmp) { 24814c299ca3SMark Lord struct ata_link *link = &ap->pmp_link[pmp]; 24824c299ca3SMark Lord 24834c299ca3SMark Lord pmp_map &= ~this_pmp; 24844c299ca3SMark Lord ehi = &link->eh_info; 24854c299ca3SMark Lord ata_ehi_clear_desc(ehi); 24864c299ca3SMark Lord ata_ehi_push_desc(ehi, "dev err"); 24874c299ca3SMark Lord ehi->err_mask |= AC_ERR_DEV; 24884c299ca3SMark Lord ehi->action |= ATA_EH_RESET; 24894c299ca3SMark Lord ata_link_abort(link); 24904c299ca3SMark Lord } 24914c299ca3SMark Lord } 24924c299ca3SMark Lord } 24934c299ca3SMark Lord 249406aaca3fSMark Lord static int mv_req_q_empty(struct ata_port *ap) 249506aaca3fSMark Lord { 249606aaca3fSMark Lord void __iomem *port_mmio = mv_ap_base(ap); 249706aaca3fSMark Lord u32 in_ptr, out_ptr; 249806aaca3fSMark Lord 2499cae5a29dSMark Lord in_ptr = (readl(port_mmio + EDMA_REQ_Q_IN_PTR) 250006aaca3fSMark Lord >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 2501cae5a29dSMark Lord out_ptr = (readl(port_mmio + EDMA_REQ_Q_OUT_PTR) 250206aaca3fSMark Lord >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 250306aaca3fSMark Lord return (in_ptr == out_ptr); /* 1 == queue_is_empty */ 250406aaca3fSMark Lord } 250506aaca3fSMark Lord 25064c299ca3SMark Lord static int mv_handle_fbs_ncq_dev_err(struct ata_port *ap) 25074c299ca3SMark Lord { 25084c299ca3SMark Lord struct mv_port_priv *pp = ap->private_data; 25094c299ca3SMark Lord int failed_links; 25104c299ca3SMark Lord unsigned int old_map, new_map; 25114c299ca3SMark Lord 25124c299ca3SMark Lord /* 25134c299ca3SMark Lord * Device error during FBS+NCQ operation: 25144c299ca3SMark Lord * 25154c299ca3SMark Lord * Set a port flag to prevent further I/O being enqueued. 25164c299ca3SMark Lord * Leave the EDMA running to drain outstanding commands from this port. 25174c299ca3SMark Lord * Perform the post-mortem/EH only when all responses are complete. 25184c299ca3SMark Lord * Follow recovery sequence from 6042/7042 datasheet (7.3.15.4.2.2). 25194c299ca3SMark Lord */ 25204c299ca3SMark Lord if (!(pp->pp_flags & MV_PP_FLAG_DELAYED_EH)) { 25214c299ca3SMark Lord pp->pp_flags |= MV_PP_FLAG_DELAYED_EH; 25224c299ca3SMark Lord pp->delayed_eh_pmp_map = 0; 25234c299ca3SMark Lord } 25244c299ca3SMark Lord old_map = pp->delayed_eh_pmp_map; 25254c299ca3SMark Lord new_map = old_map | mv_get_err_pmp_map(ap); 25264c299ca3SMark Lord 25274c299ca3SMark Lord if (old_map != new_map) { 25284c299ca3SMark Lord pp->delayed_eh_pmp_map = new_map; 25294c299ca3SMark Lord mv_pmp_eh_prep(ap, new_map & ~old_map); 25304c299ca3SMark Lord } 2531c46938ccSMark Lord failed_links = hweight16(new_map); 25324c299ca3SMark Lord 2533a9a79dfeSJoe Perches ata_port_info(ap, 2534a9a79dfeSJoe Perches "%s: pmp_map=%04x qc_map=%04x failed_links=%d nr_active_links=%d\n", 25354c299ca3SMark Lord __func__, pp->delayed_eh_pmp_map, 25364c299ca3SMark Lord ap->qc_active, failed_links, 25374c299ca3SMark Lord ap->nr_active_links); 25384c299ca3SMark Lord 253906aaca3fSMark Lord if (ap->nr_active_links <= failed_links && mv_req_q_empty(ap)) { 25404c299ca3SMark Lord mv_process_crpb_entries(ap, pp); 25414c299ca3SMark Lord mv_stop_edma(ap); 25424c299ca3SMark Lord mv_eh_freeze(ap); 2543a9a79dfeSJoe Perches ata_port_info(ap, "%s: done\n", __func__); 25444c299ca3SMark Lord return 1; /* handled */ 25454c299ca3SMark Lord } 2546a9a79dfeSJoe Perches ata_port_info(ap, "%s: waiting\n", __func__); 25474c299ca3SMark Lord return 1; /* handled */ 25484c299ca3SMark Lord } 25494c299ca3SMark Lord 25504c299ca3SMark Lord static int mv_handle_fbs_non_ncq_dev_err(struct ata_port *ap) 25514c299ca3SMark Lord { 25524c299ca3SMark Lord /* 25534c299ca3SMark Lord * Possible future enhancement: 25544c299ca3SMark Lord * 25554c299ca3SMark Lord * FBS+non-NCQ operation is not yet implemented. 25564c299ca3SMark Lord * See related notes in mv_edma_cfg(). 25574c299ca3SMark Lord * 25584c299ca3SMark Lord * Device error during FBS+non-NCQ operation: 25594c299ca3SMark Lord * 25604c299ca3SMark Lord * We need to snapshot the shadow registers for each failed command. 25614c299ca3SMark Lord * Follow recovery sequence from 6042/7042 datasheet (7.3.15.4.2.3). 25624c299ca3SMark Lord */ 25634c299ca3SMark Lord return 0; /* not handled */ 25644c299ca3SMark Lord } 25654c299ca3SMark Lord 25664c299ca3SMark Lord static int mv_handle_dev_err(struct ata_port *ap, u32 edma_err_cause) 25674c299ca3SMark Lord { 25684c299ca3SMark Lord struct mv_port_priv *pp = ap->private_data; 25694c299ca3SMark Lord 25704c299ca3SMark Lord if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) 25714c299ca3SMark Lord return 0; /* EDMA was not active: not handled */ 25724c299ca3SMark Lord if (!(pp->pp_flags & MV_PP_FLAG_FBS_EN)) 25734c299ca3SMark Lord return 0; /* FBS was not active: not handled */ 25744c299ca3SMark Lord 25754c299ca3SMark Lord if (!(edma_err_cause & EDMA_ERR_DEV)) 25764c299ca3SMark Lord return 0; /* non DEV error: not handled */ 25774c299ca3SMark Lord edma_err_cause &= ~EDMA_ERR_IRQ_TRANSIENT; 25784c299ca3SMark Lord if (edma_err_cause & ~(EDMA_ERR_DEV | EDMA_ERR_SELF_DIS)) 25794c299ca3SMark Lord return 0; /* other problems: not handled */ 25804c299ca3SMark Lord 25814c299ca3SMark Lord if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) { 25824c299ca3SMark Lord /* 25834c299ca3SMark Lord * EDMA should NOT have self-disabled for this case. 25844c299ca3SMark Lord * If it did, then something is wrong elsewhere, 25854c299ca3SMark Lord * and we cannot handle it here. 25864c299ca3SMark Lord */ 25874c299ca3SMark Lord if (edma_err_cause & EDMA_ERR_SELF_DIS) { 2588a9a79dfeSJoe Perches ata_port_warn(ap, "%s: err_cause=0x%x pp_flags=0x%x\n", 25894c299ca3SMark Lord __func__, edma_err_cause, pp->pp_flags); 25904c299ca3SMark Lord return 0; /* not handled */ 25914c299ca3SMark Lord } 25924c299ca3SMark Lord return mv_handle_fbs_ncq_dev_err(ap); 25934c299ca3SMark Lord } else { 25944c299ca3SMark Lord /* 25954c299ca3SMark Lord * EDMA should have self-disabled for this case. 25964c299ca3SMark Lord * If it did not, then something is wrong elsewhere, 25974c299ca3SMark Lord * and we cannot handle it here. 25984c299ca3SMark Lord */ 25994c299ca3SMark Lord if (!(edma_err_cause & EDMA_ERR_SELF_DIS)) { 2600a9a79dfeSJoe Perches ata_port_warn(ap, "%s: err_cause=0x%x pp_flags=0x%x\n", 26014c299ca3SMark Lord __func__, edma_err_cause, pp->pp_flags); 26024c299ca3SMark Lord return 0; /* not handled */ 26034c299ca3SMark Lord } 26044c299ca3SMark Lord return mv_handle_fbs_non_ncq_dev_err(ap); 26054c299ca3SMark Lord } 26064c299ca3SMark Lord return 0; /* not handled */ 26074c299ca3SMark Lord } 26084c299ca3SMark Lord 2609a9010329SMark Lord static void mv_unexpected_intr(struct ata_port *ap, int edma_was_enabled) 26108f767f8aSMark Lord { 26118f767f8aSMark Lord struct ata_eh_info *ehi = &ap->link.eh_info; 2612a9010329SMark Lord char *when = "idle"; 26138f767f8aSMark Lord 26148f767f8aSMark Lord ata_ehi_clear_desc(ehi); 26153e4ec344STejun Heo if (edma_was_enabled) { 2616a9010329SMark Lord when = "EDMA enabled"; 26178f767f8aSMark Lord } else { 26188f767f8aSMark Lord struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag); 26198f767f8aSMark Lord if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) 2620a9010329SMark Lord when = "polling"; 26218f767f8aSMark Lord } 2622a9010329SMark Lord ata_ehi_push_desc(ehi, "unexpected device interrupt while %s", when); 26238f767f8aSMark Lord ehi->err_mask |= AC_ERR_OTHER; 26248f767f8aSMark Lord ehi->action |= ATA_EH_RESET; 26258f767f8aSMark Lord ata_port_freeze(ap); 26268f767f8aSMark Lord } 26278f767f8aSMark Lord 2628c6fd2807SJeff Garzik /** 2629c6fd2807SJeff Garzik * mv_err_intr - Handle error interrupts on the port 2630c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 2631c6fd2807SJeff Garzik * 26328d07379dSMark Lord * Most cases require a full reset of the chip's state machine, 26338d07379dSMark Lord * which also performs a COMRESET. 26348d07379dSMark Lord * Also, if the port disabled DMA, update our cached copy to match. 2635c6fd2807SJeff Garzik * 2636c6fd2807SJeff Garzik * LOCKING: 2637c6fd2807SJeff Garzik * Inherited from caller. 2638c6fd2807SJeff Garzik */ 263937b9046aSMark Lord static void mv_err_intr(struct ata_port *ap) 2640c6fd2807SJeff Garzik { 2641c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2642bdd4dddeSJeff Garzik u32 edma_err_cause, eh_freeze_mask, serr = 0; 2643e4006077SMark Lord u32 fis_cause = 0; 2644bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 2645bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2646bdd4dddeSJeff Garzik unsigned int action = 0, err_mask = 0; 26479af5c9c9STejun Heo struct ata_eh_info *ehi = &ap->link.eh_info; 264837b9046aSMark Lord struct ata_queued_cmd *qc; 264937b9046aSMark Lord int abort = 0; 2650c6fd2807SJeff Garzik 26518d07379dSMark Lord /* 265237b9046aSMark Lord * Read and clear the SError and err_cause bits. 2653e4006077SMark Lord * For GenIIe, if EDMA_ERR_TRANS_IRQ_7 is set, we also must read/clear 2654e4006077SMark Lord * the FIS_IRQ_CAUSE register before clearing edma_err_cause. 2655bdd4dddeSJeff Garzik */ 265637b9046aSMark Lord sata_scr_read(&ap->link, SCR_ERROR, &serr); 265737b9046aSMark Lord sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 265837b9046aSMark Lord 2659cae5a29dSMark Lord edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE); 2660e4006077SMark Lord if (IS_GEN_IIE(hpriv) && (edma_err_cause & EDMA_ERR_TRANS_IRQ_7)) { 2661cae5a29dSMark Lord fis_cause = readl(port_mmio + FIS_IRQ_CAUSE); 2662cae5a29dSMark Lord writelfl(~fis_cause, port_mmio + FIS_IRQ_CAUSE); 2663e4006077SMark Lord } 2664cae5a29dSMark Lord writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE); 2665bdd4dddeSJeff Garzik 26664c299ca3SMark Lord if (edma_err_cause & EDMA_ERR_DEV) { 26674c299ca3SMark Lord /* 26684c299ca3SMark Lord * Device errors during FIS-based switching operation 26694c299ca3SMark Lord * require special handling. 26704c299ca3SMark Lord */ 26714c299ca3SMark Lord if (mv_handle_dev_err(ap, edma_err_cause)) 26724c299ca3SMark Lord return; 26734c299ca3SMark Lord } 26744c299ca3SMark Lord 267537b9046aSMark Lord qc = mv_get_active_qc(ap); 267637b9046aSMark Lord ata_ehi_clear_desc(ehi); 267737b9046aSMark Lord ata_ehi_push_desc(ehi, "edma_err_cause=%08x pp_flags=%08x", 267837b9046aSMark Lord edma_err_cause, pp->pp_flags); 2679e4006077SMark Lord 2680c443c500SMark Lord if (IS_GEN_IIE(hpriv) && (edma_err_cause & EDMA_ERR_TRANS_IRQ_7)) { 2681e4006077SMark Lord ata_ehi_push_desc(ehi, "fis_cause=%08x", fis_cause); 2682cae5a29dSMark Lord if (fis_cause & FIS_IRQ_CAUSE_AN) { 2683c443c500SMark Lord u32 ec = edma_err_cause & 2684c443c500SMark Lord ~(EDMA_ERR_TRANS_IRQ_7 | EDMA_ERR_IRQ_TRANSIENT); 2685c443c500SMark Lord sata_async_notification(ap); 2686c443c500SMark Lord if (!ec) 2687c443c500SMark Lord return; /* Just an AN; no need for the nukes */ 2688c443c500SMark Lord ata_ehi_push_desc(ehi, "SDB notify"); 2689c443c500SMark Lord } 2690c443c500SMark Lord } 2691bdd4dddeSJeff Garzik /* 2692352fab70SMark Lord * All generations share these EDMA error cause bits: 2693bdd4dddeSJeff Garzik */ 269437b9046aSMark Lord if (edma_err_cause & EDMA_ERR_DEV) { 2695bdd4dddeSJeff Garzik err_mask |= AC_ERR_DEV; 269637b9046aSMark Lord action |= ATA_EH_RESET; 269737b9046aSMark Lord ata_ehi_push_desc(ehi, "dev error"); 269837b9046aSMark Lord } 2699bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 27006c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR | 2701bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR)) { 2702bdd4dddeSJeff Garzik err_mask |= AC_ERR_ATA_BUS; 2703cf480626STejun Heo action |= ATA_EH_RESET; 2704b64bbc39STejun Heo ata_ehi_push_desc(ehi, "parity error"); 2705bdd4dddeSJeff Garzik } 2706bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { 2707bdd4dddeSJeff Garzik ata_ehi_hotplugged(ehi); 2708bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? 2709b64bbc39STejun Heo "dev disconnect" : "dev connect"); 2710cf480626STejun Heo action |= ATA_EH_RESET; 2711bdd4dddeSJeff Garzik } 2712bdd4dddeSJeff Garzik 2713352fab70SMark Lord /* 2714352fab70SMark Lord * Gen-I has a different SELF_DIS bit, 2715352fab70SMark Lord * different FREEZE bits, and no SERR bit: 2716352fab70SMark Lord */ 2717ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) { 2718bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE_5; 2719bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 2720c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 2721b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 2722c6fd2807SJeff Garzik } 2723bdd4dddeSJeff Garzik } else { 2724bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE; 2725bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS) { 2726bdd4dddeSJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 2727b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 2728bdd4dddeSJeff Garzik } 2729bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SERR) { 27308d07379dSMark Lord ata_ehi_push_desc(ehi, "SError=%08x", serr); 27318d07379dSMark Lord err_mask |= AC_ERR_ATA_BUS; 2732cf480626STejun Heo action |= ATA_EH_RESET; 2733bdd4dddeSJeff Garzik } 2734bdd4dddeSJeff Garzik } 2735c6fd2807SJeff Garzik 2736bdd4dddeSJeff Garzik if (!err_mask) { 2737bdd4dddeSJeff Garzik err_mask = AC_ERR_OTHER; 2738cf480626STejun Heo action |= ATA_EH_RESET; 2739bdd4dddeSJeff Garzik } 2740bdd4dddeSJeff Garzik 2741bdd4dddeSJeff Garzik ehi->serror |= serr; 2742bdd4dddeSJeff Garzik ehi->action |= action; 2743bdd4dddeSJeff Garzik 2744bdd4dddeSJeff Garzik if (qc) 2745bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 2746bdd4dddeSJeff Garzik else 2747bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 2748bdd4dddeSJeff Garzik 274937b9046aSMark Lord if (err_mask == AC_ERR_DEV) { 275037b9046aSMark Lord /* 275137b9046aSMark Lord * Cannot do ata_port_freeze() here, 275237b9046aSMark Lord * because it would kill PIO access, 275337b9046aSMark Lord * which is needed for further diagnosis. 275437b9046aSMark Lord */ 275537b9046aSMark Lord mv_eh_freeze(ap); 275637b9046aSMark Lord abort = 1; 275737b9046aSMark Lord } else if (edma_err_cause & eh_freeze_mask) { 275837b9046aSMark Lord /* 275937b9046aSMark Lord * Note to self: ata_port_freeze() calls ata_port_abort() 276037b9046aSMark Lord */ 2761bdd4dddeSJeff Garzik ata_port_freeze(ap); 276237b9046aSMark Lord } else { 276337b9046aSMark Lord abort = 1; 276437b9046aSMark Lord } 276537b9046aSMark Lord 276637b9046aSMark Lord if (abort) { 276737b9046aSMark Lord if (qc) 276837b9046aSMark Lord ata_link_abort(qc->dev->link); 2769bdd4dddeSJeff Garzik else 2770bdd4dddeSJeff Garzik ata_port_abort(ap); 2771bdd4dddeSJeff Garzik } 277237b9046aSMark Lord } 2773bdd4dddeSJeff Garzik 27741aadf5c3STejun Heo static bool mv_process_crpb_response(struct ata_port *ap, 2775fcfb1f77SMark Lord struct mv_crpb *response, unsigned int tag, int ncq_enabled) 2776fcfb1f77SMark Lord { 2777fcfb1f77SMark Lord u8 ata_status; 2778fcfb1f77SMark Lord u16 edma_status = le16_to_cpu(response->flags); 2779752e386cSTejun Heo 2780fcfb1f77SMark Lord /* 2781fcfb1f77SMark Lord * edma_status from a response queue entry: 2782cae5a29dSMark Lord * LSB is from EDMA_ERR_IRQ_CAUSE (non-NCQ only). 2783fcfb1f77SMark Lord * MSB is saved ATA status from command completion. 2784fcfb1f77SMark Lord */ 2785fcfb1f77SMark Lord if (!ncq_enabled) { 2786fcfb1f77SMark Lord u8 err_cause = edma_status & 0xff & ~EDMA_ERR_DEV; 2787fcfb1f77SMark Lord if (err_cause) { 2788fcfb1f77SMark Lord /* 2789752e386cSTejun Heo * Error will be seen/handled by 2790752e386cSTejun Heo * mv_err_intr(). So do nothing at all here. 2791fcfb1f77SMark Lord */ 27921aadf5c3STejun Heo return false; 2793fcfb1f77SMark Lord } 2794fcfb1f77SMark Lord } 2795fcfb1f77SMark Lord ata_status = edma_status >> CRPB_FLAG_STATUS_SHIFT; 279637b9046aSMark Lord if (!ac_err_mask(ata_status)) 27971aadf5c3STejun Heo return true; 279837b9046aSMark Lord /* else: leave it for mv_err_intr() */ 27991aadf5c3STejun Heo return false; 2800fcfb1f77SMark Lord } 2801fcfb1f77SMark Lord 2802fcfb1f77SMark Lord static void mv_process_crpb_entries(struct ata_port *ap, struct mv_port_priv *pp) 2803bdd4dddeSJeff Garzik { 2804bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2805bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2806fcfb1f77SMark Lord u32 in_index; 2807bdd4dddeSJeff Garzik bool work_done = false; 28081aadf5c3STejun Heo u32 done_mask = 0; 2809fcfb1f77SMark Lord int ncq_enabled = (pp->pp_flags & MV_PP_FLAG_NCQ_EN); 2810bdd4dddeSJeff Garzik 2811fcfb1f77SMark Lord /* Get the hardware queue position index */ 2812cae5a29dSMark Lord in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR) 2813bdd4dddeSJeff Garzik >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 2814bdd4dddeSJeff Garzik 2815fcfb1f77SMark Lord /* Process new responses from since the last time we looked */ 2816fcfb1f77SMark Lord while (in_index != pp->resp_idx) { 28176c1153e0SJeff Garzik unsigned int tag; 2818fcfb1f77SMark Lord struct mv_crpb *response = &pp->crpb[pp->resp_idx]; 2819bdd4dddeSJeff Garzik 2820fcfb1f77SMark Lord pp->resp_idx = (pp->resp_idx + 1) & MV_MAX_Q_DEPTH_MASK; 2821bdd4dddeSJeff Garzik 2822fcfb1f77SMark Lord if (IS_GEN_I(hpriv)) { 2823fcfb1f77SMark Lord /* 50xx: no NCQ, only one command active at a time */ 28249af5c9c9STejun Heo tag = ap->link.active_tag; 2825fcfb1f77SMark Lord } else { 2826fcfb1f77SMark Lord /* Gen II/IIE: get command tag from CRPB entry */ 2827fcfb1f77SMark Lord tag = le16_to_cpu(response->id) & 0x1f; 2828bdd4dddeSJeff Garzik } 28291aadf5c3STejun Heo if (mv_process_crpb_response(ap, response, tag, ncq_enabled)) 28301aadf5c3STejun Heo done_mask |= 1 << tag; 2831bdd4dddeSJeff Garzik work_done = true; 2832bdd4dddeSJeff Garzik } 2833bdd4dddeSJeff Garzik 28341aadf5c3STejun Heo if (work_done) { 28351aadf5c3STejun Heo ata_qc_complete_multiple(ap, ap->qc_active ^ done_mask); 28361aadf5c3STejun Heo 2837352fab70SMark Lord /* Update the software queue position index in hardware */ 2838bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 2839fcfb1f77SMark Lord (pp->resp_idx << EDMA_RSP_Q_PTR_SHIFT), 2840cae5a29dSMark Lord port_mmio + EDMA_RSP_Q_OUT_PTR); 2841c6fd2807SJeff Garzik } 28421aadf5c3STejun Heo } 2843c6fd2807SJeff Garzik 2844a9010329SMark Lord static void mv_port_intr(struct ata_port *ap, u32 port_cause) 2845a9010329SMark Lord { 2846a9010329SMark Lord struct mv_port_priv *pp; 2847a9010329SMark Lord int edma_was_enabled; 2848a9010329SMark Lord 2849a9010329SMark Lord /* 2850a9010329SMark Lord * Grab a snapshot of the EDMA_EN flag setting, 2851a9010329SMark Lord * so that we have a consistent view for this port, 2852a9010329SMark Lord * even if something we call of our routines changes it. 2853a9010329SMark Lord */ 2854a9010329SMark Lord pp = ap->private_data; 2855a9010329SMark Lord edma_was_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN); 2856a9010329SMark Lord /* 2857a9010329SMark Lord * Process completed CRPB response(s) before other events. 2858a9010329SMark Lord */ 2859a9010329SMark Lord if (edma_was_enabled && (port_cause & DONE_IRQ)) { 2860a9010329SMark Lord mv_process_crpb_entries(ap, pp); 28614c299ca3SMark Lord if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH) 28624c299ca3SMark Lord mv_handle_fbs_ncq_dev_err(ap); 2863a9010329SMark Lord } 2864a9010329SMark Lord /* 2865a9010329SMark Lord * Handle chip-reported errors, or continue on to handle PIO. 2866a9010329SMark Lord */ 2867a9010329SMark Lord if (unlikely(port_cause & ERR_IRQ)) { 2868a9010329SMark Lord mv_err_intr(ap); 2869a9010329SMark Lord } else if (!edma_was_enabled) { 2870a9010329SMark Lord struct ata_queued_cmd *qc = mv_get_active_qc(ap); 2871a9010329SMark Lord if (qc) 2872c3b28894STejun Heo ata_bmdma_port_intr(ap, qc); 2873a9010329SMark Lord else 2874a9010329SMark Lord mv_unexpected_intr(ap, edma_was_enabled); 2875a9010329SMark Lord } 2876a9010329SMark Lord } 2877a9010329SMark Lord 2878c6fd2807SJeff Garzik /** 2879c6fd2807SJeff Garzik * mv_host_intr - Handle all interrupts on the given host controller 2880cca3974eSJeff Garzik * @host: host specific structure 28817368f919SMark Lord * @main_irq_cause: Main interrupt cause register for the chip. 2882c6fd2807SJeff Garzik * 2883c6fd2807SJeff Garzik * LOCKING: 2884c6fd2807SJeff Garzik * Inherited from caller. 2885c6fd2807SJeff Garzik */ 28867368f919SMark Lord static int mv_host_intr(struct ata_host *host, u32 main_irq_cause) 2887c6fd2807SJeff Garzik { 2888f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 2889eabd5eb1SMark Lord void __iomem *mmio = hpriv->base, *hc_mmio; 2890a3718c1fSMark Lord unsigned int handled = 0, port; 2891c6fd2807SJeff Garzik 28922b748a0aSMark Lord /* If asserted, clear the "all ports" IRQ coalescing bit */ 28932b748a0aSMark Lord if (main_irq_cause & ALL_PORTS_COAL_DONE) 2894cae5a29dSMark Lord writel(~ALL_PORTS_COAL_IRQ, mmio + IRQ_COAL_CAUSE); 28952b748a0aSMark Lord 2896a3718c1fSMark Lord for (port = 0; port < hpriv->n_ports; port++) { 2897cca3974eSJeff Garzik struct ata_port *ap = host->ports[port]; 2898eabd5eb1SMark Lord unsigned int p, shift, hardport, port_cause; 2899eabd5eb1SMark Lord 2900a3718c1fSMark Lord MV_PORT_TO_SHIFT_AND_HARDPORT(port, shift, hardport); 2901a3718c1fSMark Lord /* 2902eabd5eb1SMark Lord * Each hc within the host has its own hc_irq_cause register, 2903eabd5eb1SMark Lord * where the interrupting ports bits get ack'd. 2904a3718c1fSMark Lord */ 2905eabd5eb1SMark Lord if (hardport == 0) { /* first port on this hc ? */ 2906eabd5eb1SMark Lord u32 hc_cause = (main_irq_cause >> shift) & HC0_IRQ_PEND; 2907eabd5eb1SMark Lord u32 port_mask, ack_irqs; 2908eabd5eb1SMark Lord /* 2909eabd5eb1SMark Lord * Skip this entire hc if nothing pending for any ports 2910eabd5eb1SMark Lord */ 2911eabd5eb1SMark Lord if (!hc_cause) { 2912eabd5eb1SMark Lord port += MV_PORTS_PER_HC - 1; 2913eabd5eb1SMark Lord continue; 2914eabd5eb1SMark Lord } 2915eabd5eb1SMark Lord /* 2916eabd5eb1SMark Lord * We don't need/want to read the hc_irq_cause register, 2917eabd5eb1SMark Lord * because doing so hurts performance, and 2918eabd5eb1SMark Lord * main_irq_cause already gives us everything we need. 2919eabd5eb1SMark Lord * 2920eabd5eb1SMark Lord * But we do have to *write* to the hc_irq_cause to ack 2921eabd5eb1SMark Lord * the ports that we are handling this time through. 2922eabd5eb1SMark Lord * 2923eabd5eb1SMark Lord * This requires that we create a bitmap for those 2924eabd5eb1SMark Lord * ports which interrupted us, and use that bitmap 2925eabd5eb1SMark Lord * to ack (only) those ports via hc_irq_cause. 2926eabd5eb1SMark Lord */ 2927eabd5eb1SMark Lord ack_irqs = 0; 29282b748a0aSMark Lord if (hc_cause & PORTS_0_3_COAL_DONE) 29292b748a0aSMark Lord ack_irqs = HC_COAL_IRQ; 2930eabd5eb1SMark Lord for (p = 0; p < MV_PORTS_PER_HC; ++p) { 2931eabd5eb1SMark Lord if ((port + p) >= hpriv->n_ports) 2932eabd5eb1SMark Lord break; 2933eabd5eb1SMark Lord port_mask = (DONE_IRQ | ERR_IRQ) << (p * 2); 2934eabd5eb1SMark Lord if (hc_cause & port_mask) 2935eabd5eb1SMark Lord ack_irqs |= (DMA_IRQ | DEV_IRQ) << p; 2936eabd5eb1SMark Lord } 2937a3718c1fSMark Lord hc_mmio = mv_hc_base_from_port(mmio, port); 2938cae5a29dSMark Lord writelfl(~ack_irqs, hc_mmio + HC_IRQ_CAUSE); 2939a3718c1fSMark Lord handled = 1; 2940a3718c1fSMark Lord } 2941a9010329SMark Lord /* 2942a9010329SMark Lord * Handle interrupts signalled for this port: 2943a9010329SMark Lord */ 2944eabd5eb1SMark Lord port_cause = (main_irq_cause >> shift) & (DONE_IRQ | ERR_IRQ); 2945a9010329SMark Lord if (port_cause) 2946a9010329SMark Lord mv_port_intr(ap, port_cause); 2947eabd5eb1SMark Lord } 2948a3718c1fSMark Lord return handled; 2949c6fd2807SJeff Garzik } 2950c6fd2807SJeff Garzik 2951a3718c1fSMark Lord static int mv_pci_error(struct ata_host *host, void __iomem *mmio) 2952bdd4dddeSJeff Garzik { 295302a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 2954bdd4dddeSJeff Garzik struct ata_port *ap; 2955bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 2956bdd4dddeSJeff Garzik struct ata_eh_info *ehi; 2957bdd4dddeSJeff Garzik unsigned int i, err_mask, printed = 0; 2958bdd4dddeSJeff Garzik u32 err_cause; 2959bdd4dddeSJeff Garzik 2960cae5a29dSMark Lord err_cause = readl(mmio + hpriv->irq_cause_offset); 2961bdd4dddeSJeff Garzik 2962a44fec1fSJoe Perches dev_err(host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", err_cause); 2963bdd4dddeSJeff Garzik 2964bdd4dddeSJeff Garzik DPRINTK("All regs @ PCI error\n"); 2965bdd4dddeSJeff Garzik mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 2966bdd4dddeSJeff Garzik 2967cae5a29dSMark Lord writelfl(0, mmio + hpriv->irq_cause_offset); 2968bdd4dddeSJeff Garzik 2969bdd4dddeSJeff Garzik for (i = 0; i < host->n_ports; i++) { 2970bdd4dddeSJeff Garzik ap = host->ports[i]; 2971936fd732STejun Heo if (!ata_link_offline(&ap->link)) { 29729af5c9c9STejun Heo ehi = &ap->link.eh_info; 2973bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 2974bdd4dddeSJeff Garzik if (!printed++) 2975bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, 2976bdd4dddeSJeff Garzik "PCI err cause 0x%08x", err_cause); 2977bdd4dddeSJeff Garzik err_mask = AC_ERR_HOST_BUS; 2978cf480626STejun Heo ehi->action = ATA_EH_RESET; 29799af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 2980bdd4dddeSJeff Garzik if (qc) 2981bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 2982bdd4dddeSJeff Garzik else 2983bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 2984bdd4dddeSJeff Garzik 2985bdd4dddeSJeff Garzik ata_port_freeze(ap); 2986bdd4dddeSJeff Garzik } 2987bdd4dddeSJeff Garzik } 2988a3718c1fSMark Lord return 1; /* handled */ 2989bdd4dddeSJeff Garzik } 2990bdd4dddeSJeff Garzik 2991c6fd2807SJeff Garzik /** 2992c5d3e45aSJeff Garzik * mv_interrupt - Main interrupt event handler 2993c6fd2807SJeff Garzik * @irq: unused 2994c6fd2807SJeff Garzik * @dev_instance: private data; in this case the host structure 2995c6fd2807SJeff Garzik * 2996c6fd2807SJeff Garzik * Read the read only register to determine if any host 2997c6fd2807SJeff Garzik * controllers have pending interrupts. If so, call lower level 2998c6fd2807SJeff Garzik * routine to handle. Also check for PCI errors which are only 2999c6fd2807SJeff Garzik * reported here. 3000c6fd2807SJeff Garzik * 3001c6fd2807SJeff Garzik * LOCKING: 3002cca3974eSJeff Garzik * This routine holds the host lock while processing pending 3003c6fd2807SJeff Garzik * interrupts. 3004c6fd2807SJeff Garzik */ 30057d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance) 3006c6fd2807SJeff Garzik { 3007cca3974eSJeff Garzik struct ata_host *host = dev_instance; 3008f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 3009a3718c1fSMark Lord unsigned int handled = 0; 30106d3c30efSMark Lord int using_msi = hpriv->hp_flags & MV_HP_FLAG_MSI; 301196e2c487SMark Lord u32 main_irq_cause, pending_irqs; 3012c6fd2807SJeff Garzik 3013646a4da5SMark Lord spin_lock(&host->lock); 30146d3c30efSMark Lord 30156d3c30efSMark Lord /* for MSI: block new interrupts while in here */ 30166d3c30efSMark Lord if (using_msi) 30172b748a0aSMark Lord mv_write_main_irq_mask(0, hpriv); 30186d3c30efSMark Lord 30197368f919SMark Lord main_irq_cause = readl(hpriv->main_irq_cause_addr); 302096e2c487SMark Lord pending_irqs = main_irq_cause & hpriv->main_irq_mask; 3021352fab70SMark Lord /* 3022352fab70SMark Lord * Deal with cases where we either have nothing pending, or have read 3023352fab70SMark Lord * a bogus register value which can indicate HW removal or PCI fault. 3024c6fd2807SJeff Garzik */ 3025a44253d2SMark Lord if (pending_irqs && main_irq_cause != 0xffffffffU) { 30261f398472SMark Lord if (unlikely((pending_irqs & PCI_ERR) && !IS_SOC(hpriv))) 3027a3718c1fSMark Lord handled = mv_pci_error(host, hpriv->base); 3028a3718c1fSMark Lord else 3029a44253d2SMark Lord handled = mv_host_intr(host, pending_irqs); 3030bdd4dddeSJeff Garzik } 30316d3c30efSMark Lord 30326d3c30efSMark Lord /* for MSI: unmask; interrupt cause bits will retrigger now */ 30336d3c30efSMark Lord if (using_msi) 30342b748a0aSMark Lord mv_write_main_irq_mask(hpriv->main_irq_mask, hpriv); 30356d3c30efSMark Lord 30369d51af7bSMark Lord spin_unlock(&host->lock); 30379d51af7bSMark Lord 3038c6fd2807SJeff Garzik return IRQ_RETVAL(handled); 3039c6fd2807SJeff Garzik } 3040c6fd2807SJeff Garzik 3041c6fd2807SJeff Garzik static unsigned int mv5_scr_offset(unsigned int sc_reg_in) 3042c6fd2807SJeff Garzik { 3043c6fd2807SJeff Garzik unsigned int ofs; 3044c6fd2807SJeff Garzik 3045c6fd2807SJeff Garzik switch (sc_reg_in) { 3046c6fd2807SJeff Garzik case SCR_STATUS: 3047c6fd2807SJeff Garzik case SCR_ERROR: 3048c6fd2807SJeff Garzik case SCR_CONTROL: 3049c6fd2807SJeff Garzik ofs = sc_reg_in * sizeof(u32); 3050c6fd2807SJeff Garzik break; 3051c6fd2807SJeff Garzik default: 3052c6fd2807SJeff Garzik ofs = 0xffffffffU; 3053c6fd2807SJeff Garzik break; 3054c6fd2807SJeff Garzik } 3055c6fd2807SJeff Garzik return ofs; 3056c6fd2807SJeff Garzik } 3057c6fd2807SJeff Garzik 305882ef04fbSTejun Heo static int mv5_scr_read(struct ata_link *link, unsigned int sc_reg_in, u32 *val) 3059c6fd2807SJeff Garzik { 306082ef04fbSTejun Heo struct mv_host_priv *hpriv = link->ap->host->private_data; 3061f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 306282ef04fbSTejun Heo void __iomem *addr = mv5_phy_base(mmio, link->ap->port_no); 3063c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 3064c6fd2807SJeff Garzik 3065da3dbb17STejun Heo if (ofs != 0xffffffffU) { 3066da3dbb17STejun Heo *val = readl(addr + ofs); 3067da3dbb17STejun Heo return 0; 3068da3dbb17STejun Heo } else 3069da3dbb17STejun Heo return -EINVAL; 3070c6fd2807SJeff Garzik } 3071c6fd2807SJeff Garzik 307282ef04fbSTejun Heo static int mv5_scr_write(struct ata_link *link, unsigned int sc_reg_in, u32 val) 3073c6fd2807SJeff Garzik { 307482ef04fbSTejun Heo struct mv_host_priv *hpriv = link->ap->host->private_data; 3075f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 307682ef04fbSTejun Heo void __iomem *addr = mv5_phy_base(mmio, link->ap->port_no); 3077c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 3078c6fd2807SJeff Garzik 3079da3dbb17STejun Heo if (ofs != 0xffffffffU) { 30800d5ff566STejun Heo writelfl(val, addr + ofs); 3081da3dbb17STejun Heo return 0; 3082da3dbb17STejun Heo } else 3083da3dbb17STejun Heo return -EINVAL; 3084c6fd2807SJeff Garzik } 3085c6fd2807SJeff Garzik 30867bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio) 3087c6fd2807SJeff Garzik { 30887bb3c529SSaeed Bishara struct pci_dev *pdev = to_pci_dev(host->dev); 3089c6fd2807SJeff Garzik int early_5080; 3090c6fd2807SJeff Garzik 309144c10138SAuke Kok early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0); 3092c6fd2807SJeff Garzik 3093c6fd2807SJeff Garzik if (!early_5080) { 3094c6fd2807SJeff Garzik u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 3095c6fd2807SJeff Garzik tmp |= (1 << 0); 3096c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 3097c6fd2807SJeff Garzik } 3098c6fd2807SJeff Garzik 30997bb3c529SSaeed Bishara mv_reset_pci_bus(host, mmio); 3100c6fd2807SJeff Garzik } 3101c6fd2807SJeff Garzik 3102c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 3103c6fd2807SJeff Garzik { 3104cae5a29dSMark Lord writel(0x0fcfffff, mmio + FLASH_CTL); 3105c6fd2807SJeff Garzik } 3106c6fd2807SJeff Garzik 3107c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 3108c6fd2807SJeff Garzik void __iomem *mmio) 3109c6fd2807SJeff Garzik { 3110c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, idx); 3111c6fd2807SJeff Garzik u32 tmp; 3112c6fd2807SJeff Garzik 3113c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 3114c6fd2807SJeff Garzik 3115c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ 3116c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ 3117c6fd2807SJeff Garzik } 3118c6fd2807SJeff Garzik 3119c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 3120c6fd2807SJeff Garzik { 3121c6fd2807SJeff Garzik u32 tmp; 3122c6fd2807SJeff Garzik 3123cae5a29dSMark Lord writel(0, mmio + GPIO_PORT_CTL); 3124c6fd2807SJeff Garzik 3125c6fd2807SJeff Garzik /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ 3126c6fd2807SJeff Garzik 3127c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 3128c6fd2807SJeff Garzik tmp |= ~(1 << 0); 3129c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 3130c6fd2807SJeff Garzik } 3131c6fd2807SJeff Garzik 3132c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 3133c6fd2807SJeff Garzik unsigned int port) 3134c6fd2807SJeff Garzik { 3135c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, port); 3136c6fd2807SJeff Garzik const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); 3137c6fd2807SJeff Garzik u32 tmp; 3138c6fd2807SJeff Garzik int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); 3139c6fd2807SJeff Garzik 3140c6fd2807SJeff Garzik if (fix_apm_sq) { 3141cae5a29dSMark Lord tmp = readl(phy_mmio + MV5_LTMODE); 3142c6fd2807SJeff Garzik tmp |= (1 << 19); 3143cae5a29dSMark Lord writel(tmp, phy_mmio + MV5_LTMODE); 3144c6fd2807SJeff Garzik 3145cae5a29dSMark Lord tmp = readl(phy_mmio + MV5_PHY_CTL); 3146c6fd2807SJeff Garzik tmp &= ~0x3; 3147c6fd2807SJeff Garzik tmp |= 0x1; 3148cae5a29dSMark Lord writel(tmp, phy_mmio + MV5_PHY_CTL); 3149c6fd2807SJeff Garzik } 3150c6fd2807SJeff Garzik 3151c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 3152c6fd2807SJeff Garzik tmp &= ~mask; 3153c6fd2807SJeff Garzik tmp |= hpriv->signal[port].pre; 3154c6fd2807SJeff Garzik tmp |= hpriv->signal[port].amps; 3155c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_MODE); 3156c6fd2807SJeff Garzik } 3157c6fd2807SJeff Garzik 3158c6fd2807SJeff Garzik 3159c6fd2807SJeff Garzik #undef ZERO 3160c6fd2807SJeff Garzik #define ZERO(reg) writel(0, port_mmio + (reg)) 3161c6fd2807SJeff Garzik static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, 3162c6fd2807SJeff Garzik unsigned int port) 3163c6fd2807SJeff Garzik { 3164c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 3165c6fd2807SJeff Garzik 3166e12bef50SMark Lord mv_reset_channel(hpriv, mmio, port); 3167c6fd2807SJeff Garzik 3168c6fd2807SJeff Garzik ZERO(0x028); /* command */ 3169cae5a29dSMark Lord writel(0x11f, port_mmio + EDMA_CFG); 3170c6fd2807SJeff Garzik ZERO(0x004); /* timer */ 3171c6fd2807SJeff Garzik ZERO(0x008); /* irq err cause */ 3172c6fd2807SJeff Garzik ZERO(0x00c); /* irq err mask */ 3173c6fd2807SJeff Garzik ZERO(0x010); /* rq bah */ 3174c6fd2807SJeff Garzik ZERO(0x014); /* rq inp */ 3175c6fd2807SJeff Garzik ZERO(0x018); /* rq outp */ 3176c6fd2807SJeff Garzik ZERO(0x01c); /* respq bah */ 3177c6fd2807SJeff Garzik ZERO(0x024); /* respq outp */ 3178c6fd2807SJeff Garzik ZERO(0x020); /* respq inp */ 3179c6fd2807SJeff Garzik ZERO(0x02c); /* test control */ 3180cae5a29dSMark Lord writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 3181c6fd2807SJeff Garzik } 3182c6fd2807SJeff Garzik #undef ZERO 3183c6fd2807SJeff Garzik 3184c6fd2807SJeff Garzik #define ZERO(reg) writel(0, hc_mmio + (reg)) 3185c6fd2807SJeff Garzik static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 3186c6fd2807SJeff Garzik unsigned int hc) 3187c6fd2807SJeff Garzik { 3188c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 3189c6fd2807SJeff Garzik u32 tmp; 3190c6fd2807SJeff Garzik 3191c6fd2807SJeff Garzik ZERO(0x00c); 3192c6fd2807SJeff Garzik ZERO(0x010); 3193c6fd2807SJeff Garzik ZERO(0x014); 3194c6fd2807SJeff Garzik ZERO(0x018); 3195c6fd2807SJeff Garzik 3196c6fd2807SJeff Garzik tmp = readl(hc_mmio + 0x20); 3197c6fd2807SJeff Garzik tmp &= 0x1c1c1c1c; 3198c6fd2807SJeff Garzik tmp |= 0x03030303; 3199c6fd2807SJeff Garzik writel(tmp, hc_mmio + 0x20); 3200c6fd2807SJeff Garzik } 3201c6fd2807SJeff Garzik #undef ZERO 3202c6fd2807SJeff Garzik 3203c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 3204c6fd2807SJeff Garzik unsigned int n_hc) 3205c6fd2807SJeff Garzik { 3206c6fd2807SJeff Garzik unsigned int hc, port; 3207c6fd2807SJeff Garzik 3208c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 3209c6fd2807SJeff Garzik for (port = 0; port < MV_PORTS_PER_HC; port++) 3210c6fd2807SJeff Garzik mv5_reset_hc_port(hpriv, mmio, 3211c6fd2807SJeff Garzik (hc * MV_PORTS_PER_HC) + port); 3212c6fd2807SJeff Garzik 3213c6fd2807SJeff Garzik mv5_reset_one_hc(hpriv, mmio, hc); 3214c6fd2807SJeff Garzik } 3215c6fd2807SJeff Garzik 3216c6fd2807SJeff Garzik return 0; 3217c6fd2807SJeff Garzik } 3218c6fd2807SJeff Garzik 3219c6fd2807SJeff Garzik #undef ZERO 3220c6fd2807SJeff Garzik #define ZERO(reg) writel(0, mmio + (reg)) 32217bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio) 3222c6fd2807SJeff Garzik { 322302a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 3224c6fd2807SJeff Garzik u32 tmp; 3225c6fd2807SJeff Garzik 3226cae5a29dSMark Lord tmp = readl(mmio + MV_PCI_MODE); 3227c6fd2807SJeff Garzik tmp &= 0xff00ffff; 3228cae5a29dSMark Lord writel(tmp, mmio + MV_PCI_MODE); 3229c6fd2807SJeff Garzik 3230c6fd2807SJeff Garzik ZERO(MV_PCI_DISC_TIMER); 3231c6fd2807SJeff Garzik ZERO(MV_PCI_MSI_TRIGGER); 3232cae5a29dSMark Lord writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 3233c6fd2807SJeff Garzik ZERO(MV_PCI_SERR_MASK); 3234cae5a29dSMark Lord ZERO(hpriv->irq_cause_offset); 3235cae5a29dSMark Lord ZERO(hpriv->irq_mask_offset); 3236c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_LOW_ADDRESS); 3237c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_HIGH_ADDRESS); 3238c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_ATTRIBUTE); 3239c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_COMMAND); 3240c6fd2807SJeff Garzik } 3241c6fd2807SJeff Garzik #undef ZERO 3242c6fd2807SJeff Garzik 3243c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 3244c6fd2807SJeff Garzik { 3245c6fd2807SJeff Garzik u32 tmp; 3246c6fd2807SJeff Garzik 3247c6fd2807SJeff Garzik mv5_reset_flash(hpriv, mmio); 3248c6fd2807SJeff Garzik 3249cae5a29dSMark Lord tmp = readl(mmio + GPIO_PORT_CTL); 3250c6fd2807SJeff Garzik tmp &= 0x3; 3251c6fd2807SJeff Garzik tmp |= (1 << 5) | (1 << 6); 3252cae5a29dSMark Lord writel(tmp, mmio + GPIO_PORT_CTL); 3253c6fd2807SJeff Garzik } 3254c6fd2807SJeff Garzik 3255c6fd2807SJeff Garzik /** 3256c6fd2807SJeff Garzik * mv6_reset_hc - Perform the 6xxx global soft reset 3257c6fd2807SJeff Garzik * @mmio: base address of the HBA 3258c6fd2807SJeff Garzik * 3259c6fd2807SJeff Garzik * This routine only applies to 6xxx parts. 3260c6fd2807SJeff Garzik * 3261c6fd2807SJeff Garzik * LOCKING: 3262c6fd2807SJeff Garzik * Inherited from caller. 3263c6fd2807SJeff Garzik */ 3264c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 3265c6fd2807SJeff Garzik unsigned int n_hc) 3266c6fd2807SJeff Garzik { 3267cae5a29dSMark Lord void __iomem *reg = mmio + PCI_MAIN_CMD_STS; 3268c6fd2807SJeff Garzik int i, rc = 0; 3269c6fd2807SJeff Garzik u32 t; 3270c6fd2807SJeff Garzik 3271c6fd2807SJeff Garzik /* Following procedure defined in PCI "main command and status 3272c6fd2807SJeff Garzik * register" table. 3273c6fd2807SJeff Garzik */ 3274c6fd2807SJeff Garzik t = readl(reg); 3275c6fd2807SJeff Garzik writel(t | STOP_PCI_MASTER, reg); 3276c6fd2807SJeff Garzik 3277c6fd2807SJeff Garzik for (i = 0; i < 1000; i++) { 3278c6fd2807SJeff Garzik udelay(1); 3279c6fd2807SJeff Garzik t = readl(reg); 32802dcb407eSJeff Garzik if (PCI_MASTER_EMPTY & t) 3281c6fd2807SJeff Garzik break; 3282c6fd2807SJeff Garzik } 3283c6fd2807SJeff Garzik if (!(PCI_MASTER_EMPTY & t)) { 3284c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); 3285c6fd2807SJeff Garzik rc = 1; 3286c6fd2807SJeff Garzik goto done; 3287c6fd2807SJeff Garzik } 3288c6fd2807SJeff Garzik 3289c6fd2807SJeff Garzik /* set reset */ 3290c6fd2807SJeff Garzik i = 5; 3291c6fd2807SJeff Garzik do { 3292c6fd2807SJeff Garzik writel(t | GLOB_SFT_RST, reg); 3293c6fd2807SJeff Garzik t = readl(reg); 3294c6fd2807SJeff Garzik udelay(1); 3295c6fd2807SJeff Garzik } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 3296c6fd2807SJeff Garzik 3297c6fd2807SJeff Garzik if (!(GLOB_SFT_RST & t)) { 3298c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't set global reset\n"); 3299c6fd2807SJeff Garzik rc = 1; 3300c6fd2807SJeff Garzik goto done; 3301c6fd2807SJeff Garzik } 3302c6fd2807SJeff Garzik 3303c6fd2807SJeff Garzik /* clear reset and *reenable the PCI master* (not mentioned in spec) */ 3304c6fd2807SJeff Garzik i = 5; 3305c6fd2807SJeff Garzik do { 3306c6fd2807SJeff Garzik writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); 3307c6fd2807SJeff Garzik t = readl(reg); 3308c6fd2807SJeff Garzik udelay(1); 3309c6fd2807SJeff Garzik } while ((GLOB_SFT_RST & t) && (i-- > 0)); 3310c6fd2807SJeff Garzik 3311c6fd2807SJeff Garzik if (GLOB_SFT_RST & t) { 3312c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 3313c6fd2807SJeff Garzik rc = 1; 3314c6fd2807SJeff Garzik } 3315c6fd2807SJeff Garzik done: 3316c6fd2807SJeff Garzik return rc; 3317c6fd2807SJeff Garzik } 3318c6fd2807SJeff Garzik 3319c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 3320c6fd2807SJeff Garzik void __iomem *mmio) 3321c6fd2807SJeff Garzik { 3322c6fd2807SJeff Garzik void __iomem *port_mmio; 3323c6fd2807SJeff Garzik u32 tmp; 3324c6fd2807SJeff Garzik 3325cae5a29dSMark Lord tmp = readl(mmio + RESET_CFG); 3326c6fd2807SJeff Garzik if ((tmp & (1 << 0)) == 0) { 3327c6fd2807SJeff Garzik hpriv->signal[idx].amps = 0x7 << 8; 3328c6fd2807SJeff Garzik hpriv->signal[idx].pre = 0x1 << 5; 3329c6fd2807SJeff Garzik return; 3330c6fd2807SJeff Garzik } 3331c6fd2807SJeff Garzik 3332c6fd2807SJeff Garzik port_mmio = mv_port_base(mmio, idx); 3333c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE2); 3334c6fd2807SJeff Garzik 3335c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 3336c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 3337c6fd2807SJeff Garzik } 3338c6fd2807SJeff Garzik 3339c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 3340c6fd2807SJeff Garzik { 3341cae5a29dSMark Lord writel(0x00000060, mmio + GPIO_PORT_CTL); 3342c6fd2807SJeff Garzik } 3343c6fd2807SJeff Garzik 3344c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 3345c6fd2807SJeff Garzik unsigned int port) 3346c6fd2807SJeff Garzik { 3347c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 3348c6fd2807SJeff Garzik 3349c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 3350c6fd2807SJeff Garzik int fix_phy_mode2 = 3351c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 3352c6fd2807SJeff Garzik int fix_phy_mode4 = 3353c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 33548c30a8b9SMark Lord u32 m2, m3; 3355c6fd2807SJeff Garzik 3356c6fd2807SJeff Garzik if (fix_phy_mode2) { 3357c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 3358c6fd2807SJeff Garzik m2 &= ~(1 << 16); 3359c6fd2807SJeff Garzik m2 |= (1 << 31); 3360c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 3361c6fd2807SJeff Garzik 3362c6fd2807SJeff Garzik udelay(200); 3363c6fd2807SJeff Garzik 3364c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 3365c6fd2807SJeff Garzik m2 &= ~((1 << 16) | (1 << 31)); 3366c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 3367c6fd2807SJeff Garzik 3368c6fd2807SJeff Garzik udelay(200); 3369c6fd2807SJeff Garzik } 3370c6fd2807SJeff Garzik 33718c30a8b9SMark Lord /* 33728c30a8b9SMark Lord * Gen-II/IIe PHY_MODE3 errata RM#2: 33738c30a8b9SMark Lord * Achieves better receiver noise performance than the h/w default: 33748c30a8b9SMark Lord */ 33758c30a8b9SMark Lord m3 = readl(port_mmio + PHY_MODE3); 33768c30a8b9SMark Lord m3 = (m3 & 0x1f) | (0x5555601 << 5); 3377c6fd2807SJeff Garzik 33780388a8c0SMark Lord /* Guideline 88F5182 (GL# SATA-S11) */ 33790388a8c0SMark Lord if (IS_SOC(hpriv)) 33800388a8c0SMark Lord m3 &= ~0x1c; 33810388a8c0SMark Lord 3382c6fd2807SJeff Garzik if (fix_phy_mode4) { 3383ba069e37SMark Lord u32 m4 = readl(port_mmio + PHY_MODE4); 3384ba069e37SMark Lord /* 3385ba069e37SMark Lord * Enforce reserved-bit restrictions on GenIIe devices only. 3386ba069e37SMark Lord * For earlier chipsets, force only the internal config field 3387ba069e37SMark Lord * (workaround for errata FEr SATA#10 part 1). 3388ba069e37SMark Lord */ 33898c30a8b9SMark Lord if (IS_GEN_IIE(hpriv)) 3390ba069e37SMark Lord m4 = (m4 & ~PHY_MODE4_RSVD_ZEROS) | PHY_MODE4_RSVD_ONES; 3391ba069e37SMark Lord else 3392ba069e37SMark Lord m4 = (m4 & ~PHY_MODE4_CFG_MASK) | PHY_MODE4_CFG_VALUE; 33938c30a8b9SMark Lord writel(m4, port_mmio + PHY_MODE4); 3394c6fd2807SJeff Garzik } 3395b406c7a6SMark Lord /* 3396b406c7a6SMark Lord * Workaround for 60x1-B2 errata SATA#13: 3397b406c7a6SMark Lord * Any write to PHY_MODE4 (above) may corrupt PHY_MODE3, 3398b406c7a6SMark Lord * so we must always rewrite PHY_MODE3 after PHY_MODE4. 3399ba68460bSMark Lord * Or ensure we use writelfl() when writing PHY_MODE4. 3400b406c7a6SMark Lord */ 3401b406c7a6SMark Lord writel(m3, port_mmio + PHY_MODE3); 3402c6fd2807SJeff Garzik 3403c6fd2807SJeff Garzik /* Revert values of pre-emphasis and signal amps to the saved ones */ 3404c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 3405c6fd2807SJeff Garzik 3406c6fd2807SJeff Garzik m2 &= ~MV_M2_PREAMP_MASK; 3407c6fd2807SJeff Garzik m2 |= hpriv->signal[port].amps; 3408c6fd2807SJeff Garzik m2 |= hpriv->signal[port].pre; 3409c6fd2807SJeff Garzik m2 &= ~(1 << 16); 3410c6fd2807SJeff Garzik 3411c6fd2807SJeff Garzik /* according to mvSata 3.6.1, some IIE values are fixed */ 3412c6fd2807SJeff Garzik if (IS_GEN_IIE(hpriv)) { 3413c6fd2807SJeff Garzik m2 &= ~0xC30FF01F; 3414c6fd2807SJeff Garzik m2 |= 0x0000900F; 3415c6fd2807SJeff Garzik } 3416c6fd2807SJeff Garzik 3417c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 3418c6fd2807SJeff Garzik } 3419c6fd2807SJeff Garzik 3420f351b2d6SSaeed Bishara /* TODO: use the generic LED interface to configure the SATA Presence */ 3421f351b2d6SSaeed Bishara /* & Acitivy LEDs on the board */ 3422f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 3423f351b2d6SSaeed Bishara void __iomem *mmio) 3424f351b2d6SSaeed Bishara { 3425f351b2d6SSaeed Bishara return; 3426f351b2d6SSaeed Bishara } 3427f351b2d6SSaeed Bishara 3428f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 3429f351b2d6SSaeed Bishara void __iomem *mmio) 3430f351b2d6SSaeed Bishara { 3431f351b2d6SSaeed Bishara void __iomem *port_mmio; 3432f351b2d6SSaeed Bishara u32 tmp; 3433f351b2d6SSaeed Bishara 3434f351b2d6SSaeed Bishara port_mmio = mv_port_base(mmio, idx); 3435f351b2d6SSaeed Bishara tmp = readl(port_mmio + PHY_MODE2); 3436f351b2d6SSaeed Bishara 3437f351b2d6SSaeed Bishara hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 3438f351b2d6SSaeed Bishara hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 3439f351b2d6SSaeed Bishara } 3440f351b2d6SSaeed Bishara 3441f351b2d6SSaeed Bishara #undef ZERO 3442f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, port_mmio + (reg)) 3443f351b2d6SSaeed Bishara static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv, 3444f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int port) 3445f351b2d6SSaeed Bishara { 3446f351b2d6SSaeed Bishara void __iomem *port_mmio = mv_port_base(mmio, port); 3447f351b2d6SSaeed Bishara 3448e12bef50SMark Lord mv_reset_channel(hpriv, mmio, port); 3449f351b2d6SSaeed Bishara 3450f351b2d6SSaeed Bishara ZERO(0x028); /* command */ 3451cae5a29dSMark Lord writel(0x101f, port_mmio + EDMA_CFG); 3452f351b2d6SSaeed Bishara ZERO(0x004); /* timer */ 3453f351b2d6SSaeed Bishara ZERO(0x008); /* irq err cause */ 3454f351b2d6SSaeed Bishara ZERO(0x00c); /* irq err mask */ 3455f351b2d6SSaeed Bishara ZERO(0x010); /* rq bah */ 3456f351b2d6SSaeed Bishara ZERO(0x014); /* rq inp */ 3457f351b2d6SSaeed Bishara ZERO(0x018); /* rq outp */ 3458f351b2d6SSaeed Bishara ZERO(0x01c); /* respq bah */ 3459f351b2d6SSaeed Bishara ZERO(0x024); /* respq outp */ 3460f351b2d6SSaeed Bishara ZERO(0x020); /* respq inp */ 3461f351b2d6SSaeed Bishara ZERO(0x02c); /* test control */ 3462d7b0c143SSaeed Bishara writel(0x800, port_mmio + EDMA_IORDY_TMOUT); 3463f351b2d6SSaeed Bishara } 3464f351b2d6SSaeed Bishara 3465f351b2d6SSaeed Bishara #undef ZERO 3466f351b2d6SSaeed Bishara 3467f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, hc_mmio + (reg)) 3468f351b2d6SSaeed Bishara static void mv_soc_reset_one_hc(struct mv_host_priv *hpriv, 3469f351b2d6SSaeed Bishara void __iomem *mmio) 3470f351b2d6SSaeed Bishara { 3471f351b2d6SSaeed Bishara void __iomem *hc_mmio = mv_hc_base(mmio, 0); 3472f351b2d6SSaeed Bishara 3473f351b2d6SSaeed Bishara ZERO(0x00c); 3474f351b2d6SSaeed Bishara ZERO(0x010); 3475f351b2d6SSaeed Bishara ZERO(0x014); 3476f351b2d6SSaeed Bishara 3477f351b2d6SSaeed Bishara } 3478f351b2d6SSaeed Bishara 3479f351b2d6SSaeed Bishara #undef ZERO 3480f351b2d6SSaeed Bishara 3481f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 3482f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc) 3483f351b2d6SSaeed Bishara { 3484f351b2d6SSaeed Bishara unsigned int port; 3485f351b2d6SSaeed Bishara 3486f351b2d6SSaeed Bishara for (port = 0; port < hpriv->n_ports; port++) 3487f351b2d6SSaeed Bishara mv_soc_reset_hc_port(hpriv, mmio, port); 3488f351b2d6SSaeed Bishara 3489f351b2d6SSaeed Bishara mv_soc_reset_one_hc(hpriv, mmio); 3490f351b2d6SSaeed Bishara 3491f351b2d6SSaeed Bishara return 0; 3492f351b2d6SSaeed Bishara } 3493f351b2d6SSaeed Bishara 3494f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 3495f351b2d6SSaeed Bishara void __iomem *mmio) 3496f351b2d6SSaeed Bishara { 3497f351b2d6SSaeed Bishara return; 3498f351b2d6SSaeed Bishara } 3499f351b2d6SSaeed Bishara 3500f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio) 3501f351b2d6SSaeed Bishara { 3502f351b2d6SSaeed Bishara return; 3503f351b2d6SSaeed Bishara } 3504f351b2d6SSaeed Bishara 350529b7e43cSMartin Michlmayr static void mv_soc_65n_phy_errata(struct mv_host_priv *hpriv, 350629b7e43cSMartin Michlmayr void __iomem *mmio, unsigned int port) 350729b7e43cSMartin Michlmayr { 350829b7e43cSMartin Michlmayr void __iomem *port_mmio = mv_port_base(mmio, port); 350929b7e43cSMartin Michlmayr u32 reg; 351029b7e43cSMartin Michlmayr 351129b7e43cSMartin Michlmayr reg = readl(port_mmio + PHY_MODE3); 351229b7e43cSMartin Michlmayr reg &= ~(0x3 << 27); /* SELMUPF (bits 28:27) to 1 */ 351329b7e43cSMartin Michlmayr reg |= (0x1 << 27); 351429b7e43cSMartin Michlmayr reg &= ~(0x3 << 29); /* SELMUPI (bits 30:29) to 1 */ 351529b7e43cSMartin Michlmayr reg |= (0x1 << 29); 351629b7e43cSMartin Michlmayr writel(reg, port_mmio + PHY_MODE3); 351729b7e43cSMartin Michlmayr 351829b7e43cSMartin Michlmayr reg = readl(port_mmio + PHY_MODE4); 351929b7e43cSMartin Michlmayr reg &= ~0x1; /* SATU_OD8 (bit 0) to 0, reserved bit 16 must be set */ 352029b7e43cSMartin Michlmayr reg |= (0x1 << 16); 352129b7e43cSMartin Michlmayr writel(reg, port_mmio + PHY_MODE4); 352229b7e43cSMartin Michlmayr 352329b7e43cSMartin Michlmayr reg = readl(port_mmio + PHY_MODE9_GEN2); 352429b7e43cSMartin Michlmayr reg &= ~0xf; /* TXAMP[3:0] (bits 3:0) to 8 */ 352529b7e43cSMartin Michlmayr reg |= 0x8; 352629b7e43cSMartin Michlmayr reg &= ~(0x1 << 14); /* TXAMP[4] (bit 14) to 0 */ 352729b7e43cSMartin Michlmayr writel(reg, port_mmio + PHY_MODE9_GEN2); 352829b7e43cSMartin Michlmayr 352929b7e43cSMartin Michlmayr reg = readl(port_mmio + PHY_MODE9_GEN1); 353029b7e43cSMartin Michlmayr reg &= ~0xf; /* TXAMP[3:0] (bits 3:0) to 8 */ 353129b7e43cSMartin Michlmayr reg |= 0x8; 353229b7e43cSMartin Michlmayr reg &= ~(0x1 << 14); /* TXAMP[4] (bit 14) to 0 */ 353329b7e43cSMartin Michlmayr writel(reg, port_mmio + PHY_MODE9_GEN1); 353429b7e43cSMartin Michlmayr } 353529b7e43cSMartin Michlmayr 353629b7e43cSMartin Michlmayr /** 353729b7e43cSMartin Michlmayr * soc_is_65 - check if the soc is 65 nano device 353829b7e43cSMartin Michlmayr * 353929b7e43cSMartin Michlmayr * Detect the type of the SoC, this is done by reading the PHYCFG_OFS 354029b7e43cSMartin Michlmayr * register, this register should contain non-zero value and it exists only 354129b7e43cSMartin Michlmayr * in the 65 nano devices, when reading it from older devices we get 0. 354229b7e43cSMartin Michlmayr */ 354329b7e43cSMartin Michlmayr static bool soc_is_65n(struct mv_host_priv *hpriv) 354429b7e43cSMartin Michlmayr { 354529b7e43cSMartin Michlmayr void __iomem *port0_mmio = mv_port_base(hpriv->base, 0); 354629b7e43cSMartin Michlmayr 354729b7e43cSMartin Michlmayr if (readl(port0_mmio + PHYCFG_OFS)) 354829b7e43cSMartin Michlmayr return true; 354929b7e43cSMartin Michlmayr return false; 355029b7e43cSMartin Michlmayr } 355129b7e43cSMartin Michlmayr 35528e7decdbSMark Lord static void mv_setup_ifcfg(void __iomem *port_mmio, int want_gen2i) 3553b67a1064SMark Lord { 3554cae5a29dSMark Lord u32 ifcfg = readl(port_mmio + SATA_IFCFG); 3555b67a1064SMark Lord 35568e7decdbSMark Lord ifcfg = (ifcfg & 0xf7f) | 0x9b1000; /* from chip spec */ 3557b67a1064SMark Lord if (want_gen2i) 35588e7decdbSMark Lord ifcfg |= (1 << 7); /* enable gen2i speed */ 3559cae5a29dSMark Lord writelfl(ifcfg, port_mmio + SATA_IFCFG); 3560b67a1064SMark Lord } 3561b67a1064SMark Lord 3562e12bef50SMark Lord static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio, 3563c6fd2807SJeff Garzik unsigned int port_no) 3564c6fd2807SJeff Garzik { 3565c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port_no); 3566c6fd2807SJeff Garzik 35678e7decdbSMark Lord /* 35688e7decdbSMark Lord * The datasheet warns against setting EDMA_RESET when EDMA is active 35698e7decdbSMark Lord * (but doesn't say what the problem might be). So we first try 35708e7decdbSMark Lord * to disable the EDMA engine before doing the EDMA_RESET operation. 35718e7decdbSMark Lord */ 35720d8be5cbSMark Lord mv_stop_edma_engine(port_mmio); 3573cae5a29dSMark Lord writelfl(EDMA_RESET, port_mmio + EDMA_CMD); 3574c6fd2807SJeff Garzik 3575b67a1064SMark Lord if (!IS_GEN_I(hpriv)) { 35768e7decdbSMark Lord /* Enable 3.0gb/s link speed: this survives EDMA_RESET */ 35778e7decdbSMark Lord mv_setup_ifcfg(port_mmio, 1); 3578c6fd2807SJeff Garzik } 3579b67a1064SMark Lord /* 35808e7decdbSMark Lord * Strobing EDMA_RESET here causes a hard reset of the SATA transport, 3581b67a1064SMark Lord * link, and physical layers. It resets all SATA interface registers 3582cae5a29dSMark Lord * (except for SATA_IFCFG), and issues a COMRESET to the dev. 3583c6fd2807SJeff Garzik */ 3584cae5a29dSMark Lord writelfl(EDMA_RESET, port_mmio + EDMA_CMD); 3585b67a1064SMark Lord udelay(25); /* allow reset propagation */ 3586cae5a29dSMark Lord writelfl(0, port_mmio + EDMA_CMD); 3587c6fd2807SJeff Garzik 3588c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port_no); 3589c6fd2807SJeff Garzik 3590ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 3591c6fd2807SJeff Garzik mdelay(1); 3592c6fd2807SJeff Garzik } 3593c6fd2807SJeff Garzik 3594e49856d8SMark Lord static void mv_pmp_select(struct ata_port *ap, int pmp) 3595e49856d8SMark Lord { 3596e49856d8SMark Lord if (sata_pmp_supported(ap)) { 3597e49856d8SMark Lord void __iomem *port_mmio = mv_ap_base(ap); 3598cae5a29dSMark Lord u32 reg = readl(port_mmio + SATA_IFCTL); 3599e49856d8SMark Lord int old = reg & 0xf; 3600e49856d8SMark Lord 3601e49856d8SMark Lord if (old != pmp) { 3602e49856d8SMark Lord reg = (reg & ~0xf) | pmp; 3603cae5a29dSMark Lord writelfl(reg, port_mmio + SATA_IFCTL); 3604e49856d8SMark Lord } 3605e49856d8SMark Lord } 3606e49856d8SMark Lord } 3607e49856d8SMark Lord 3608e49856d8SMark Lord static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class, 3609bdd4dddeSJeff Garzik unsigned long deadline) 3610c6fd2807SJeff Garzik { 3611e49856d8SMark Lord mv_pmp_select(link->ap, sata_srst_pmp(link)); 3612e49856d8SMark Lord return sata_std_hardreset(link, class, deadline); 3613e49856d8SMark Lord } 3614c6fd2807SJeff Garzik 3615e49856d8SMark Lord static int mv_softreset(struct ata_link *link, unsigned int *class, 3616e49856d8SMark Lord unsigned long deadline) 3617da3dbb17STejun Heo { 3618e49856d8SMark Lord mv_pmp_select(link->ap, sata_srst_pmp(link)); 3619e49856d8SMark Lord return ata_sff_softreset(link, class, deadline); 3620bdd4dddeSJeff Garzik } 3621bdd4dddeSJeff Garzik 3622cc0680a5STejun Heo static int mv_hardreset(struct ata_link *link, unsigned int *class, 3623bdd4dddeSJeff Garzik unsigned long deadline) 3624bdd4dddeSJeff Garzik { 3625cc0680a5STejun Heo struct ata_port *ap = link->ap; 3626bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 3627b562468cSMark Lord struct mv_port_priv *pp = ap->private_data; 3628f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 36290d8be5cbSMark Lord int rc, attempts = 0, extra = 0; 36300d8be5cbSMark Lord u32 sstatus; 36310d8be5cbSMark Lord bool online; 3632bdd4dddeSJeff Garzik 3633e12bef50SMark Lord mv_reset_channel(hpriv, mmio, ap->port_no); 3634b562468cSMark Lord pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 3635d16ab3f6SMark Lord pp->pp_flags &= 3636d16ab3f6SMark Lord ~(MV_PP_FLAG_FBS_EN | MV_PP_FLAG_NCQ_EN | MV_PP_FLAG_FAKE_ATA_BUSY); 3637bdd4dddeSJeff Garzik 36380d8be5cbSMark Lord /* Workaround for errata FEr SATA#10 (part 2) */ 36390d8be5cbSMark Lord do { 364017c5aab5SMark Lord const unsigned long *timing = 364117c5aab5SMark Lord sata_ehc_deb_timing(&link->eh_context); 3642bdd4dddeSJeff Garzik 364317c5aab5SMark Lord rc = sata_link_hardreset(link, timing, deadline + extra, 364417c5aab5SMark Lord &online, NULL); 36459dcffd99SMark Lord rc = online ? -EAGAIN : rc; 364617c5aab5SMark Lord if (rc) 36470d8be5cbSMark Lord return rc; 36480d8be5cbSMark Lord sata_scr_read(link, SCR_STATUS, &sstatus); 36490d8be5cbSMark Lord if (!IS_GEN_I(hpriv) && ++attempts >= 5 && sstatus == 0x121) { 36500d8be5cbSMark Lord /* Force 1.5gb/s link speed and try again */ 36518e7decdbSMark Lord mv_setup_ifcfg(mv_ap_base(ap), 0); 36520d8be5cbSMark Lord if (time_after(jiffies + HZ, deadline)) 36530d8be5cbSMark Lord extra = HZ; /* only extend it once, max */ 3654bdd4dddeSJeff Garzik } 36550d8be5cbSMark Lord } while (sstatus != 0x0 && sstatus != 0x113 && sstatus != 0x123); 365608da1759SMark Lord mv_save_cached_regs(ap); 365766e57a2cSMark Lord mv_edma_cfg(ap, 0, 0); 3658bdd4dddeSJeff Garzik 365917c5aab5SMark Lord return rc; 3660bdd4dddeSJeff Garzik } 3661bdd4dddeSJeff Garzik 3662bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap) 3663c6fd2807SJeff Garzik { 36641cfd19aeSMark Lord mv_stop_edma(ap); 3665c4de573bSMark Lord mv_enable_port_irqs(ap, 0); 3666c6fd2807SJeff Garzik } 3667bdd4dddeSJeff Garzik 3668bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap) 3669bdd4dddeSJeff Garzik { 3670f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 3671c4de573bSMark Lord unsigned int port = ap->port_no; 3672c4de573bSMark Lord unsigned int hardport = mv_hardport_from_port(port); 36731cfd19aeSMark Lord void __iomem *hc_mmio = mv_hc_base_from_port(hpriv->base, port); 3674bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 3675c4de573bSMark Lord u32 hc_irq_cause; 3676bdd4dddeSJeff Garzik 3677bdd4dddeSJeff Garzik /* clear EDMA errors on this port */ 3678cae5a29dSMark Lord writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE); 3679bdd4dddeSJeff Garzik 3680bdd4dddeSJeff Garzik /* clear pending irq events */ 3681cae6edc3SMark Lord hc_irq_cause = ~((DEV_IRQ | DMA_IRQ) << hardport); 3682cae5a29dSMark Lord writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE); 3683bdd4dddeSJeff Garzik 368488e675e1SMark Lord mv_enable_port_irqs(ap, ERR_IRQ); 3685c6fd2807SJeff Garzik } 3686c6fd2807SJeff Garzik 3687c6fd2807SJeff Garzik /** 3688c6fd2807SJeff Garzik * mv_port_init - Perform some early initialization on a single port. 3689c6fd2807SJeff Garzik * @port: libata data structure storing shadow register addresses 3690c6fd2807SJeff Garzik * @port_mmio: base address of the port 3691c6fd2807SJeff Garzik * 3692c6fd2807SJeff Garzik * Initialize shadow register mmio addresses, clear outstanding 3693c6fd2807SJeff Garzik * interrupts on the port, and unmask interrupts for the future 3694c6fd2807SJeff Garzik * start of the port. 3695c6fd2807SJeff Garzik * 3696c6fd2807SJeff Garzik * LOCKING: 3697c6fd2807SJeff Garzik * Inherited from caller. 3698c6fd2807SJeff Garzik */ 3699c6fd2807SJeff Garzik static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 3700c6fd2807SJeff Garzik { 3701cae5a29dSMark Lord void __iomem *serr, *shd_base = port_mmio + SHD_BLK; 3702c6fd2807SJeff Garzik 3703c6fd2807SJeff Garzik /* PIO related setup 3704c6fd2807SJeff Garzik */ 3705c6fd2807SJeff Garzik port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); 3706c6fd2807SJeff Garzik port->error_addr = 3707c6fd2807SJeff Garzik port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); 3708c6fd2807SJeff Garzik port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); 3709c6fd2807SJeff Garzik port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); 3710c6fd2807SJeff Garzik port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); 3711c6fd2807SJeff Garzik port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); 3712c6fd2807SJeff Garzik port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); 3713c6fd2807SJeff Garzik port->status_addr = 3714c6fd2807SJeff Garzik port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); 3715c6fd2807SJeff Garzik /* special case: control/altstatus doesn't have ATA_REG_ address */ 3716cae5a29dSMark Lord port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST; 3717c6fd2807SJeff Garzik 3718c6fd2807SJeff Garzik /* Clear any currently outstanding port interrupt conditions */ 3719cae5a29dSMark Lord serr = port_mmio + mv_scr_offset(SCR_ERROR); 3720cae5a29dSMark Lord writelfl(readl(serr), serr); 3721cae5a29dSMark Lord writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE); 3722c6fd2807SJeff Garzik 3723646a4da5SMark Lord /* unmask all non-transient EDMA error interrupts */ 3724cae5a29dSMark Lord writelfl(~EDMA_ERR_IRQ_TRANSIENT, port_mmio + EDMA_ERR_IRQ_MASK); 3725c6fd2807SJeff Garzik 3726c6fd2807SJeff Garzik VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 3727cae5a29dSMark Lord readl(port_mmio + EDMA_CFG), 3728cae5a29dSMark Lord readl(port_mmio + EDMA_ERR_IRQ_CAUSE), 3729cae5a29dSMark Lord readl(port_mmio + EDMA_ERR_IRQ_MASK)); 3730c6fd2807SJeff Garzik } 3731c6fd2807SJeff Garzik 3732616d4a98SMark Lord static unsigned int mv_in_pcix_mode(struct ata_host *host) 3733616d4a98SMark Lord { 3734616d4a98SMark Lord struct mv_host_priv *hpriv = host->private_data; 3735616d4a98SMark Lord void __iomem *mmio = hpriv->base; 3736616d4a98SMark Lord u32 reg; 3737616d4a98SMark Lord 37381f398472SMark Lord if (IS_SOC(hpriv) || !IS_PCIE(hpriv)) 3739616d4a98SMark Lord return 0; /* not PCI-X capable */ 3740cae5a29dSMark Lord reg = readl(mmio + MV_PCI_MODE); 3741616d4a98SMark Lord if ((reg & MV_PCI_MODE_MASK) == 0) 3742616d4a98SMark Lord return 0; /* conventional PCI mode */ 3743616d4a98SMark Lord return 1; /* chip is in PCI-X mode */ 3744616d4a98SMark Lord } 3745616d4a98SMark Lord 3746616d4a98SMark Lord static int mv_pci_cut_through_okay(struct ata_host *host) 3747616d4a98SMark Lord { 3748616d4a98SMark Lord struct mv_host_priv *hpriv = host->private_data; 3749616d4a98SMark Lord void __iomem *mmio = hpriv->base; 3750616d4a98SMark Lord u32 reg; 3751616d4a98SMark Lord 3752616d4a98SMark Lord if (!mv_in_pcix_mode(host)) { 3753cae5a29dSMark Lord reg = readl(mmio + MV_PCI_COMMAND); 3754cae5a29dSMark Lord if (reg & MV_PCI_COMMAND_MRDTRIG) 3755616d4a98SMark Lord return 0; /* not okay */ 3756616d4a98SMark Lord } 3757616d4a98SMark Lord return 1; /* okay */ 3758616d4a98SMark Lord } 3759616d4a98SMark Lord 376065ad7fefSMark Lord static void mv_60x1b2_errata_pci7(struct ata_host *host) 376165ad7fefSMark Lord { 376265ad7fefSMark Lord struct mv_host_priv *hpriv = host->private_data; 376365ad7fefSMark Lord void __iomem *mmio = hpriv->base; 376465ad7fefSMark Lord 376565ad7fefSMark Lord /* workaround for 60x1-B2 errata PCI#7 */ 376665ad7fefSMark Lord if (mv_in_pcix_mode(host)) { 3767cae5a29dSMark Lord u32 reg = readl(mmio + MV_PCI_COMMAND); 3768cae5a29dSMark Lord writelfl(reg & ~MV_PCI_COMMAND_MWRCOM, mmio + MV_PCI_COMMAND); 376965ad7fefSMark Lord } 377065ad7fefSMark Lord } 377165ad7fefSMark Lord 37724447d351STejun Heo static int mv_chip_id(struct ata_host *host, unsigned int board_idx) 3773c6fd2807SJeff Garzik { 37744447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 37754447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 3776c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 3777c6fd2807SJeff Garzik 3778c6fd2807SJeff Garzik switch (board_idx) { 3779c6fd2807SJeff Garzik case chip_5080: 3780c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 3781ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 3782c6fd2807SJeff Garzik 378344c10138SAuke Kok switch (pdev->revision) { 3784c6fd2807SJeff Garzik case 0x1: 3785c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 3786c6fd2807SJeff Garzik break; 3787c6fd2807SJeff Garzik case 0x3: 3788c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 3789c6fd2807SJeff Garzik break; 3790c6fd2807SJeff Garzik default: 3791a44fec1fSJoe Perches dev_warn(&pdev->dev, 3792c6fd2807SJeff Garzik "Applying 50XXB2 workarounds to unknown rev\n"); 3793c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 3794c6fd2807SJeff Garzik break; 3795c6fd2807SJeff Garzik } 3796c6fd2807SJeff Garzik break; 3797c6fd2807SJeff Garzik 3798c6fd2807SJeff Garzik case chip_504x: 3799c6fd2807SJeff Garzik case chip_508x: 3800c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 3801ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 3802c6fd2807SJeff Garzik 380344c10138SAuke Kok switch (pdev->revision) { 3804c6fd2807SJeff Garzik case 0x0: 3805c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 3806c6fd2807SJeff Garzik break; 3807c6fd2807SJeff Garzik case 0x3: 3808c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 3809c6fd2807SJeff Garzik break; 3810c6fd2807SJeff Garzik default: 3811a44fec1fSJoe Perches dev_warn(&pdev->dev, 3812c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 3813c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 3814c6fd2807SJeff Garzik break; 3815c6fd2807SJeff Garzik } 3816c6fd2807SJeff Garzik break; 3817c6fd2807SJeff Garzik 3818c6fd2807SJeff Garzik case chip_604x: 3819c6fd2807SJeff Garzik case chip_608x: 3820c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 3821ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_II; 3822c6fd2807SJeff Garzik 382344c10138SAuke Kok switch (pdev->revision) { 3824c6fd2807SJeff Garzik case 0x7: 382565ad7fefSMark Lord mv_60x1b2_errata_pci7(host); 3826c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 3827c6fd2807SJeff Garzik break; 3828c6fd2807SJeff Garzik case 0x9: 3829c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 3830c6fd2807SJeff Garzik break; 3831c6fd2807SJeff Garzik default: 3832a44fec1fSJoe Perches dev_warn(&pdev->dev, 3833c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 3834c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 3835c6fd2807SJeff Garzik break; 3836c6fd2807SJeff Garzik } 3837c6fd2807SJeff Garzik break; 3838c6fd2807SJeff Garzik 3839c6fd2807SJeff Garzik case chip_7042: 3840616d4a98SMark Lord hp_flags |= MV_HP_PCIE | MV_HP_CUT_THROUGH; 3841306b30f7SMark Lord if (pdev->vendor == PCI_VENDOR_ID_TTI && 3842306b30f7SMark Lord (pdev->device == 0x2300 || pdev->device == 0x2310)) 3843306b30f7SMark Lord { 38444e520033SMark Lord /* 38454e520033SMark Lord * Highpoint RocketRAID PCIe 23xx series cards: 38464e520033SMark Lord * 38474e520033SMark Lord * Unconfigured drives are treated as "Legacy" 38484e520033SMark Lord * by the BIOS, and it overwrites sector 8 with 38494e520033SMark Lord * a "Lgcy" metadata block prior to Linux boot. 38504e520033SMark Lord * 38514e520033SMark Lord * Configured drives (RAID or JBOD) leave sector 8 38524e520033SMark Lord * alone, but instead overwrite a high numbered 38534e520033SMark Lord * sector for the RAID metadata. This sector can 38544e520033SMark Lord * be determined exactly, by truncating the physical 38554e520033SMark Lord * drive capacity to a nice even GB value. 38564e520033SMark Lord * 38574e520033SMark Lord * RAID metadata is at: (dev->n_sectors & ~0xfffff) 38584e520033SMark Lord * 38594e520033SMark Lord * Warn the user, lest they think we're just buggy. 38604e520033SMark Lord */ 38614e520033SMark Lord printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID" 38624e520033SMark Lord " BIOS CORRUPTS DATA on all attached drives," 38634e520033SMark Lord " regardless of if/how they are configured." 38644e520033SMark Lord " BEWARE!\n"); 38654e520033SMark Lord printk(KERN_WARNING DRV_NAME ": For data safety, do not" 38664e520033SMark Lord " use sectors 8-9 on \"Legacy\" drives," 38674e520033SMark Lord " and avoid the final two gigabytes on" 38684e520033SMark Lord " all RocketRAID BIOS initialized drives.\n"); 3869306b30f7SMark Lord } 38708e7decdbSMark Lord /* drop through */ 3871c6fd2807SJeff Garzik case chip_6042: 3872c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 3873c6fd2807SJeff Garzik hp_flags |= MV_HP_GEN_IIE; 3874616d4a98SMark Lord if (board_idx == chip_6042 && mv_pci_cut_through_okay(host)) 3875616d4a98SMark Lord hp_flags |= MV_HP_CUT_THROUGH; 3876c6fd2807SJeff Garzik 387744c10138SAuke Kok switch (pdev->revision) { 38785cf73bfbSMark Lord case 0x2: /* Rev.B0: the first/only public release */ 3879c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 3880c6fd2807SJeff Garzik break; 3881c6fd2807SJeff Garzik default: 3882a44fec1fSJoe Perches dev_warn(&pdev->dev, 3883c6fd2807SJeff Garzik "Applying 60X1C0 workarounds to unknown rev\n"); 3884c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 3885c6fd2807SJeff Garzik break; 3886c6fd2807SJeff Garzik } 3887c6fd2807SJeff Garzik break; 3888f351b2d6SSaeed Bishara case chip_soc: 388929b7e43cSMartin Michlmayr if (soc_is_65n(hpriv)) 389029b7e43cSMartin Michlmayr hpriv->ops = &mv_soc_65n_ops; 389129b7e43cSMartin Michlmayr else 3892f351b2d6SSaeed Bishara hpriv->ops = &mv_soc_ops; 3893eb3a55a9SSaeed Bishara hp_flags |= MV_HP_FLAG_SOC | MV_HP_GEN_IIE | 3894eb3a55a9SSaeed Bishara MV_HP_ERRATA_60X1C0; 3895f351b2d6SSaeed Bishara break; 3896c6fd2807SJeff Garzik 3897c6fd2807SJeff Garzik default: 3898a44fec1fSJoe Perches dev_err(host->dev, "BUG: invalid board index %u\n", board_idx); 3899c6fd2807SJeff Garzik return 1; 3900c6fd2807SJeff Garzik } 3901c6fd2807SJeff Garzik 3902c6fd2807SJeff Garzik hpriv->hp_flags = hp_flags; 390302a121daSMark Lord if (hp_flags & MV_HP_PCIE) { 3904cae5a29dSMark Lord hpriv->irq_cause_offset = PCIE_IRQ_CAUSE; 3905cae5a29dSMark Lord hpriv->irq_mask_offset = PCIE_IRQ_MASK; 390602a121daSMark Lord hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS; 390702a121daSMark Lord } else { 3908cae5a29dSMark Lord hpriv->irq_cause_offset = PCI_IRQ_CAUSE; 3909cae5a29dSMark Lord hpriv->irq_mask_offset = PCI_IRQ_MASK; 391002a121daSMark Lord hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS; 391102a121daSMark Lord } 3912c6fd2807SJeff Garzik 3913c6fd2807SJeff Garzik return 0; 3914c6fd2807SJeff Garzik } 3915c6fd2807SJeff Garzik 3916c6fd2807SJeff Garzik /** 3917c6fd2807SJeff Garzik * mv_init_host - Perform some early initialization of the host. 39184447d351STejun Heo * @host: ATA host to initialize 3919c6fd2807SJeff Garzik * 3920c6fd2807SJeff Garzik * If possible, do an early global reset of the host. Then do 3921c6fd2807SJeff Garzik * our port init and clear/unmask all/relevant host interrupts. 3922c6fd2807SJeff Garzik * 3923c6fd2807SJeff Garzik * LOCKING: 3924c6fd2807SJeff Garzik * Inherited from caller. 3925c6fd2807SJeff Garzik */ 39261bfeff03SSaeed Bishara static int mv_init_host(struct ata_host *host) 3927c6fd2807SJeff Garzik { 3928c6fd2807SJeff Garzik int rc = 0, n_hc, port, hc; 39294447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 3930f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 3931c6fd2807SJeff Garzik 39321bfeff03SSaeed Bishara rc = mv_chip_id(host, hpriv->board_idx); 3933c6fd2807SJeff Garzik if (rc) 3934c6fd2807SJeff Garzik goto done; 3935c6fd2807SJeff Garzik 39361f398472SMark Lord if (IS_SOC(hpriv)) { 3937cae5a29dSMark Lord hpriv->main_irq_cause_addr = mmio + SOC_HC_MAIN_IRQ_CAUSE; 3938cae5a29dSMark Lord hpriv->main_irq_mask_addr = mmio + SOC_HC_MAIN_IRQ_MASK; 39391f398472SMark Lord } else { 3940cae5a29dSMark Lord hpriv->main_irq_cause_addr = mmio + PCI_HC_MAIN_IRQ_CAUSE; 3941cae5a29dSMark Lord hpriv->main_irq_mask_addr = mmio + PCI_HC_MAIN_IRQ_MASK; 3942f351b2d6SSaeed Bishara } 3943352fab70SMark Lord 39445d0fb2e7SThomas Reitmayr /* initialize shadow irq mask with register's value */ 39455d0fb2e7SThomas Reitmayr hpriv->main_irq_mask = readl(hpriv->main_irq_mask_addr); 39465d0fb2e7SThomas Reitmayr 3947352fab70SMark Lord /* global interrupt mask: 0 == mask everything */ 3948c4de573bSMark Lord mv_set_main_irq_mask(host, ~0, 0); 3949f351b2d6SSaeed Bishara 39504447d351STejun Heo n_hc = mv_get_hc_count(host->ports[0]->flags); 3951c6fd2807SJeff Garzik 39524447d351STejun Heo for (port = 0; port < host->n_ports; port++) 395329b7e43cSMartin Michlmayr if (hpriv->ops->read_preamp) 3954c6fd2807SJeff Garzik hpriv->ops->read_preamp(hpriv, port, mmio); 3955c6fd2807SJeff Garzik 3956c6fd2807SJeff Garzik rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 3957c6fd2807SJeff Garzik if (rc) 3958c6fd2807SJeff Garzik goto done; 3959c6fd2807SJeff Garzik 3960c6fd2807SJeff Garzik hpriv->ops->reset_flash(hpriv, mmio); 39617bb3c529SSaeed Bishara hpriv->ops->reset_bus(host, mmio); 3962c6fd2807SJeff Garzik hpriv->ops->enable_leds(hpriv, mmio); 3963c6fd2807SJeff Garzik 39644447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 3965cbcdd875STejun Heo struct ata_port *ap = host->ports[port]; 3966c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 3967cbcdd875STejun Heo 3968cbcdd875STejun Heo mv_port_init(&ap->ioaddr, port_mmio); 3969c6fd2807SJeff Garzik } 3970c6fd2807SJeff Garzik 3971c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 3972c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 3973c6fd2807SJeff Garzik 3974c6fd2807SJeff Garzik VPRINTK("HC%i: HC config=0x%08x HC IRQ cause " 3975c6fd2807SJeff Garzik "(before clear)=0x%08x\n", hc, 3976cae5a29dSMark Lord readl(hc_mmio + HC_CFG), 3977cae5a29dSMark Lord readl(hc_mmio + HC_IRQ_CAUSE)); 3978c6fd2807SJeff Garzik 3979c6fd2807SJeff Garzik /* Clear any currently outstanding hc interrupt conditions */ 3980cae5a29dSMark Lord writelfl(0, hc_mmio + HC_IRQ_CAUSE); 3981c6fd2807SJeff Garzik } 3982c6fd2807SJeff Garzik 398344c65d16SMark Lord if (!IS_SOC(hpriv)) { 3984c6fd2807SJeff Garzik /* Clear any currently outstanding host interrupt conditions */ 3985cae5a29dSMark Lord writelfl(0, mmio + hpriv->irq_cause_offset); 3986c6fd2807SJeff Garzik 3987c6fd2807SJeff Garzik /* and unmask interrupt generation for host regs */ 3988cae5a29dSMark Lord writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_offset); 398944c65d16SMark Lord } 3990c6fd2807SJeff Garzik 399151de32d2SMark Lord /* 399251de32d2SMark Lord * enable only global host interrupts for now. 399351de32d2SMark Lord * The per-port interrupts get done later as ports are set up. 399451de32d2SMark Lord */ 3995c4de573bSMark Lord mv_set_main_irq_mask(host, 0, PCI_ERR); 39962b748a0aSMark Lord mv_set_irq_coalescing(host, irq_coalescing_io_count, 39972b748a0aSMark Lord irq_coalescing_usecs); 3998c6fd2807SJeff Garzik done: 3999c6fd2807SJeff Garzik return rc; 4000c6fd2807SJeff Garzik } 4001c6fd2807SJeff Garzik 4002fbf14e2fSByron Bradley static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev) 4003fbf14e2fSByron Bradley { 4004fbf14e2fSByron Bradley hpriv->crqb_pool = dmam_pool_create("crqb_q", dev, MV_CRQB_Q_SZ, 4005fbf14e2fSByron Bradley MV_CRQB_Q_SZ, 0); 4006fbf14e2fSByron Bradley if (!hpriv->crqb_pool) 4007fbf14e2fSByron Bradley return -ENOMEM; 4008fbf14e2fSByron Bradley 4009fbf14e2fSByron Bradley hpriv->crpb_pool = dmam_pool_create("crpb_q", dev, MV_CRPB_Q_SZ, 4010fbf14e2fSByron Bradley MV_CRPB_Q_SZ, 0); 4011fbf14e2fSByron Bradley if (!hpriv->crpb_pool) 4012fbf14e2fSByron Bradley return -ENOMEM; 4013fbf14e2fSByron Bradley 4014fbf14e2fSByron Bradley hpriv->sg_tbl_pool = dmam_pool_create("sg_tbl", dev, MV_SG_TBL_SZ, 4015fbf14e2fSByron Bradley MV_SG_TBL_SZ, 0); 4016fbf14e2fSByron Bradley if (!hpriv->sg_tbl_pool) 4017fbf14e2fSByron Bradley return -ENOMEM; 4018fbf14e2fSByron Bradley 4019fbf14e2fSByron Bradley return 0; 4020fbf14e2fSByron Bradley } 4021fbf14e2fSByron Bradley 402215a32632SLennert Buytenhek static void mv_conf_mbus_windows(struct mv_host_priv *hpriv, 402363a9332bSAndrew Lunn const struct mbus_dram_target_info *dram) 402415a32632SLennert Buytenhek { 402515a32632SLennert Buytenhek int i; 402615a32632SLennert Buytenhek 402715a32632SLennert Buytenhek for (i = 0; i < 4; i++) { 402815a32632SLennert Buytenhek writel(0, hpriv->base + WINDOW_CTRL(i)); 402915a32632SLennert Buytenhek writel(0, hpriv->base + WINDOW_BASE(i)); 403015a32632SLennert Buytenhek } 403115a32632SLennert Buytenhek 403215a32632SLennert Buytenhek for (i = 0; i < dram->num_cs; i++) { 403363a9332bSAndrew Lunn const struct mbus_dram_window *cs = dram->cs + i; 403415a32632SLennert Buytenhek 403515a32632SLennert Buytenhek writel(((cs->size - 1) & 0xffff0000) | 403615a32632SLennert Buytenhek (cs->mbus_attr << 8) | 403715a32632SLennert Buytenhek (dram->mbus_dram_target_id << 4) | 1, 403815a32632SLennert Buytenhek hpriv->base + WINDOW_CTRL(i)); 403915a32632SLennert Buytenhek writel(cs->base, hpriv->base + WINDOW_BASE(i)); 404015a32632SLennert Buytenhek } 404115a32632SLennert Buytenhek } 404215a32632SLennert Buytenhek 4043f351b2d6SSaeed Bishara /** 4044f351b2d6SSaeed Bishara * mv_platform_probe - handle a positive probe of an soc Marvell 4045f351b2d6SSaeed Bishara * host 4046f351b2d6SSaeed Bishara * @pdev: platform device found 4047f351b2d6SSaeed Bishara * 4048f351b2d6SSaeed Bishara * LOCKING: 4049f351b2d6SSaeed Bishara * Inherited from caller. 4050f351b2d6SSaeed Bishara */ 4051f351b2d6SSaeed Bishara static int mv_platform_probe(struct platform_device *pdev) 4052f351b2d6SSaeed Bishara { 4053f351b2d6SSaeed Bishara const struct mv_sata_platform_data *mv_platform_data; 405463a9332bSAndrew Lunn const struct mbus_dram_target_info *dram; 4055f351b2d6SSaeed Bishara const struct ata_port_info *ppi[] = 4056f351b2d6SSaeed Bishara { &mv_port_info[chip_soc], NULL }; 4057f351b2d6SSaeed Bishara struct ata_host *host; 4058f351b2d6SSaeed Bishara struct mv_host_priv *hpriv; 4059f351b2d6SSaeed Bishara struct resource *res; 406097b414e1SAndrew Lunn int n_ports = 0, irq = 0; 406199b80e97SDan Carpenter int rc; 4062eee98990SAndrew Lunn int port; 4063f351b2d6SSaeed Bishara 406406296a1eSJoe Perches ata_print_version_once(&pdev->dev, DRV_VERSION); 4065f351b2d6SSaeed Bishara 4066f351b2d6SSaeed Bishara /* 4067f351b2d6SSaeed Bishara * Simple resource validation .. 4068f351b2d6SSaeed Bishara */ 4069f351b2d6SSaeed Bishara if (unlikely(pdev->num_resources != 2)) { 4070f351b2d6SSaeed Bishara dev_err(&pdev->dev, "invalid number of resources\n"); 4071f351b2d6SSaeed Bishara return -EINVAL; 4072f351b2d6SSaeed Bishara } 4073f351b2d6SSaeed Bishara 4074f351b2d6SSaeed Bishara /* 4075f351b2d6SSaeed Bishara * Get the register base first 4076f351b2d6SSaeed Bishara */ 4077f351b2d6SSaeed Bishara res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 4078f351b2d6SSaeed Bishara if (res == NULL) 4079f351b2d6SSaeed Bishara return -EINVAL; 4080f351b2d6SSaeed Bishara 4081f351b2d6SSaeed Bishara /* allocate host */ 408297b414e1SAndrew Lunn if (pdev->dev.of_node) { 408397b414e1SAndrew Lunn of_property_read_u32(pdev->dev.of_node, "nr-ports", &n_ports); 408497b414e1SAndrew Lunn irq = irq_of_parse_and_map(pdev->dev.of_node, 0); 408597b414e1SAndrew Lunn } else { 408661b8c345SJingoo Han mv_platform_data = dev_get_platdata(&pdev->dev); 4087f351b2d6SSaeed Bishara n_ports = mv_platform_data->n_ports; 408897b414e1SAndrew Lunn irq = platform_get_irq(pdev, 0); 408997b414e1SAndrew Lunn } 4090f351b2d6SSaeed Bishara 4091f351b2d6SSaeed Bishara host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 4092f351b2d6SSaeed Bishara hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 4093f351b2d6SSaeed Bishara 4094f351b2d6SSaeed Bishara if (!host || !hpriv) 4095f351b2d6SSaeed Bishara return -ENOMEM; 4096eee98990SAndrew Lunn hpriv->port_clks = devm_kzalloc(&pdev->dev, 4097eee98990SAndrew Lunn sizeof(struct clk *) * n_ports, 4098eee98990SAndrew Lunn GFP_KERNEL); 4099eee98990SAndrew Lunn if (!hpriv->port_clks) 4100eee98990SAndrew Lunn return -ENOMEM; 4101b7db4f2eSAndrew Lunn hpriv->port_phys = devm_kzalloc(&pdev->dev, 4102b7db4f2eSAndrew Lunn sizeof(struct phy *) * n_ports, 4103b7db4f2eSAndrew Lunn GFP_KERNEL); 4104b7db4f2eSAndrew Lunn if (!hpriv->port_phys) 4105b7db4f2eSAndrew Lunn return -ENOMEM; 4106f351b2d6SSaeed Bishara host->private_data = hpriv; 41071bfeff03SSaeed Bishara hpriv->board_idx = chip_soc; 4108f351b2d6SSaeed Bishara 4109f351b2d6SSaeed Bishara host->iomap = NULL; 4110f1cb0ea1SSaeed Bishara hpriv->base = devm_ioremap(&pdev->dev, res->start, 4111041b5eacSJulia Lawall resource_size(res)); 4112cae5a29dSMark Lord hpriv->base -= SATAHC0_REG_BASE; 4113f351b2d6SSaeed Bishara 4114c77a2f4eSSaeed Bishara hpriv->clk = clk_get(&pdev->dev, NULL); 4115c77a2f4eSSaeed Bishara if (IS_ERR(hpriv->clk)) 4116eee98990SAndrew Lunn dev_notice(&pdev->dev, "cannot get optional clkdev\n"); 4117c77a2f4eSSaeed Bishara else 4118eee98990SAndrew Lunn clk_prepare_enable(hpriv->clk); 4119eee98990SAndrew Lunn 4120eee98990SAndrew Lunn for (port = 0; port < n_ports; port++) { 4121eee98990SAndrew Lunn char port_number[16]; 4122eee98990SAndrew Lunn sprintf(port_number, "%d", port); 4123eee98990SAndrew Lunn hpriv->port_clks[port] = clk_get(&pdev->dev, port_number); 4124eee98990SAndrew Lunn if (!IS_ERR(hpriv->port_clks[port])) 4125eee98990SAndrew Lunn clk_prepare_enable(hpriv->port_clks[port]); 4126b7db4f2eSAndrew Lunn 4127b7db4f2eSAndrew Lunn sprintf(port_number, "port%d", port); 4128b7db4f2eSAndrew Lunn hpriv->port_phys[port] = devm_phy_get(&pdev->dev, port_number); 4129b7db4f2eSAndrew Lunn if (IS_ERR(hpriv->port_phys[port])) { 4130b7db4f2eSAndrew Lunn rc = PTR_ERR(hpriv->port_phys[port]); 4131b7db4f2eSAndrew Lunn hpriv->port_phys[port] = NULL; 4132b7db4f2eSAndrew Lunn if ((rc != -EPROBE_DEFER) && (rc != -ENODEV)) 4133b7db4f2eSAndrew Lunn dev_warn(&pdev->dev, "error getting phy"); 4134*8ad116e6SEzequiel Garcia 4135*8ad116e6SEzequiel Garcia /* Cleanup only the initialized ports */ 4136*8ad116e6SEzequiel Garcia hpriv->n_ports = port; 4137b7db4f2eSAndrew Lunn goto err; 4138b7db4f2eSAndrew Lunn } else 4139b7db4f2eSAndrew Lunn phy_power_on(hpriv->port_phys[port]); 4140eee98990SAndrew Lunn } 4141c77a2f4eSSaeed Bishara 4142*8ad116e6SEzequiel Garcia /* All the ports have been initialized */ 4143*8ad116e6SEzequiel Garcia hpriv->n_ports = n_ports; 4144*8ad116e6SEzequiel Garcia 414515a32632SLennert Buytenhek /* 414615a32632SLennert Buytenhek * (Re-)program MBUS remapping windows if we are asked to. 414715a32632SLennert Buytenhek */ 414863a9332bSAndrew Lunn dram = mv_mbus_dram_info(); 414963a9332bSAndrew Lunn if (dram) 415063a9332bSAndrew Lunn mv_conf_mbus_windows(hpriv, dram); 415115a32632SLennert Buytenhek 4152fbf14e2fSByron Bradley rc = mv_create_dma_pools(hpriv, &pdev->dev); 4153fbf14e2fSByron Bradley if (rc) 4154c77a2f4eSSaeed Bishara goto err; 4155fbf14e2fSByron Bradley 41569013d64eSLior Amsalem /* 41579013d64eSLior Amsalem * To allow disk hotplug on Armada 370/XP SoCs, the PHY speed must be 41589013d64eSLior Amsalem * updated in the LP_PHY_CTL register. 41599013d64eSLior Amsalem */ 41609013d64eSLior Amsalem if (pdev->dev.of_node && 41619013d64eSLior Amsalem of_device_is_compatible(pdev->dev.of_node, 41629013d64eSLior Amsalem "marvell,armada-370-sata")) 41639013d64eSLior Amsalem hpriv->hp_flags |= MV_HP_FIX_LP_PHY_CTL; 41649013d64eSLior Amsalem 4165f351b2d6SSaeed Bishara /* initialize adapter */ 41661bfeff03SSaeed Bishara rc = mv_init_host(host); 4167f351b2d6SSaeed Bishara if (rc) 4168c77a2f4eSSaeed Bishara goto err; 4169f351b2d6SSaeed Bishara 4170a44fec1fSJoe Perches dev_info(&pdev->dev, "slots %u ports %d\n", 4171a44fec1fSJoe Perches (unsigned)MV_MAX_Q_DEPTH, host->n_ports); 4172f351b2d6SSaeed Bishara 417397b414e1SAndrew Lunn rc = ata_host_activate(host, irq, mv_interrupt, IRQF_SHARED, &mv6_sht); 4174c00a4c9dSSergei Shtylyov if (!rc) 4175c00a4c9dSSergei Shtylyov return 0; 4176c00a4c9dSSergei Shtylyov 4177c77a2f4eSSaeed Bishara err: 4178c77a2f4eSSaeed Bishara if (!IS_ERR(hpriv->clk)) { 4179eee98990SAndrew Lunn clk_disable_unprepare(hpriv->clk); 4180c77a2f4eSSaeed Bishara clk_put(hpriv->clk); 4181c77a2f4eSSaeed Bishara } 4182*8ad116e6SEzequiel Garcia for (port = 0; port < hpriv->n_ports; port++) { 4183eee98990SAndrew Lunn if (!IS_ERR(hpriv->port_clks[port])) { 4184eee98990SAndrew Lunn clk_disable_unprepare(hpriv->port_clks[port]); 4185eee98990SAndrew Lunn clk_put(hpriv->port_clks[port]); 4186eee98990SAndrew Lunn } 4187b7db4f2eSAndrew Lunn if (hpriv->port_phys[port]) 4188b7db4f2eSAndrew Lunn phy_power_off(hpriv->port_phys[port]); 4189eee98990SAndrew Lunn } 4190c77a2f4eSSaeed Bishara 4191c77a2f4eSSaeed Bishara return rc; 4192f351b2d6SSaeed Bishara } 4193f351b2d6SSaeed Bishara 4194f351b2d6SSaeed Bishara /* 4195f351b2d6SSaeed Bishara * 4196f351b2d6SSaeed Bishara * mv_platform_remove - unplug a platform interface 4197f351b2d6SSaeed Bishara * @pdev: platform device 4198f351b2d6SSaeed Bishara * 4199f351b2d6SSaeed Bishara * A platform bus SATA device has been unplugged. Perform the needed 4200f351b2d6SSaeed Bishara * cleanup. Also called on module unload for any active devices. 4201f351b2d6SSaeed Bishara */ 42020ec24914SGreg Kroah-Hartman static int mv_platform_remove(struct platform_device *pdev) 4203f351b2d6SSaeed Bishara { 4204d8661921SSergei Shtylyov struct ata_host *host = platform_get_drvdata(pdev); 4205c77a2f4eSSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 4206eee98990SAndrew Lunn int port; 4207f351b2d6SSaeed Bishara ata_host_detach(host); 4208c77a2f4eSSaeed Bishara 4209c77a2f4eSSaeed Bishara if (!IS_ERR(hpriv->clk)) { 4210eee98990SAndrew Lunn clk_disable_unprepare(hpriv->clk); 4211c77a2f4eSSaeed Bishara clk_put(hpriv->clk); 4212c77a2f4eSSaeed Bishara } 4213eee98990SAndrew Lunn for (port = 0; port < host->n_ports; port++) { 4214eee98990SAndrew Lunn if (!IS_ERR(hpriv->port_clks[port])) { 4215eee98990SAndrew Lunn clk_disable_unprepare(hpriv->port_clks[port]); 4216eee98990SAndrew Lunn clk_put(hpriv->port_clks[port]); 4217eee98990SAndrew Lunn } 4218b7db4f2eSAndrew Lunn if (hpriv->port_phys[port]) 4219b7db4f2eSAndrew Lunn phy_power_off(hpriv->port_phys[port]); 4220eee98990SAndrew Lunn } 4221f351b2d6SSaeed Bishara return 0; 4222f351b2d6SSaeed Bishara } 4223f351b2d6SSaeed Bishara 42246481f2b5SSaeed Bishara #ifdef CONFIG_PM 42256481f2b5SSaeed Bishara static int mv_platform_suspend(struct platform_device *pdev, pm_message_t state) 42266481f2b5SSaeed Bishara { 4227d8661921SSergei Shtylyov struct ata_host *host = platform_get_drvdata(pdev); 42286481f2b5SSaeed Bishara if (host) 42296481f2b5SSaeed Bishara return ata_host_suspend(host, state); 42306481f2b5SSaeed Bishara else 42316481f2b5SSaeed Bishara return 0; 42326481f2b5SSaeed Bishara } 42336481f2b5SSaeed Bishara 42346481f2b5SSaeed Bishara static int mv_platform_resume(struct platform_device *pdev) 42356481f2b5SSaeed Bishara { 4236d8661921SSergei Shtylyov struct ata_host *host = platform_get_drvdata(pdev); 423763a9332bSAndrew Lunn const struct mbus_dram_target_info *dram; 42386481f2b5SSaeed Bishara int ret; 42396481f2b5SSaeed Bishara 42406481f2b5SSaeed Bishara if (host) { 42416481f2b5SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 424263a9332bSAndrew Lunn 42436481f2b5SSaeed Bishara /* 42446481f2b5SSaeed Bishara * (Re-)program MBUS remapping windows if we are asked to. 42456481f2b5SSaeed Bishara */ 424663a9332bSAndrew Lunn dram = mv_mbus_dram_info(); 424763a9332bSAndrew Lunn if (dram) 424863a9332bSAndrew Lunn mv_conf_mbus_windows(hpriv, dram); 42496481f2b5SSaeed Bishara 42506481f2b5SSaeed Bishara /* initialize adapter */ 42511bfeff03SSaeed Bishara ret = mv_init_host(host); 42526481f2b5SSaeed Bishara if (ret) { 42536481f2b5SSaeed Bishara printk(KERN_ERR DRV_NAME ": Error during HW init\n"); 42546481f2b5SSaeed Bishara return ret; 42556481f2b5SSaeed Bishara } 42566481f2b5SSaeed Bishara ata_host_resume(host); 42576481f2b5SSaeed Bishara } 42586481f2b5SSaeed Bishara 42596481f2b5SSaeed Bishara return 0; 42606481f2b5SSaeed Bishara } 42616481f2b5SSaeed Bishara #else 42626481f2b5SSaeed Bishara #define mv_platform_suspend NULL 42636481f2b5SSaeed Bishara #define mv_platform_resume NULL 42646481f2b5SSaeed Bishara #endif 42656481f2b5SSaeed Bishara 426697b414e1SAndrew Lunn #ifdef CONFIG_OF 42670ec24914SGreg Kroah-Hartman static struct of_device_id mv_sata_dt_ids[] = { 4268b1f5c73bSSimon Guinot { .compatible = "marvell,armada-370-sata", }, 426997b414e1SAndrew Lunn { .compatible = "marvell,orion-sata", }, 427097b414e1SAndrew Lunn {}, 427197b414e1SAndrew Lunn }; 427297b414e1SAndrew Lunn MODULE_DEVICE_TABLE(of, mv_sata_dt_ids); 427397b414e1SAndrew Lunn #endif 427497b414e1SAndrew Lunn 4275f351b2d6SSaeed Bishara static struct platform_driver mv_platform_driver = { 4276f351b2d6SSaeed Bishara .probe = mv_platform_probe, 42770ec24914SGreg Kroah-Hartman .remove = mv_platform_remove, 42786481f2b5SSaeed Bishara .suspend = mv_platform_suspend, 42796481f2b5SSaeed Bishara .resume = mv_platform_resume, 4280f351b2d6SSaeed Bishara .driver = { 4281f351b2d6SSaeed Bishara .name = DRV_NAME, 4282f351b2d6SSaeed Bishara .owner = THIS_MODULE, 428397b414e1SAndrew Lunn .of_match_table = of_match_ptr(mv_sata_dt_ids), 4284f351b2d6SSaeed Bishara }, 4285f351b2d6SSaeed Bishara }; 4286f351b2d6SSaeed Bishara 4287f351b2d6SSaeed Bishara 42887bb3c529SSaeed Bishara #ifdef CONFIG_PCI 4289f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 4290f351b2d6SSaeed Bishara const struct pci_device_id *ent); 4291b2dec48cSSaeed Bishara #ifdef CONFIG_PM 4292b2dec48cSSaeed Bishara static int mv_pci_device_resume(struct pci_dev *pdev); 4293b2dec48cSSaeed Bishara #endif 4294f351b2d6SSaeed Bishara 42957bb3c529SSaeed Bishara 42967bb3c529SSaeed Bishara static struct pci_driver mv_pci_driver = { 42977bb3c529SSaeed Bishara .name = DRV_NAME, 42987bb3c529SSaeed Bishara .id_table = mv_pci_tbl, 4299f351b2d6SSaeed Bishara .probe = mv_pci_init_one, 43007bb3c529SSaeed Bishara .remove = ata_pci_remove_one, 4301b2dec48cSSaeed Bishara #ifdef CONFIG_PM 4302b2dec48cSSaeed Bishara .suspend = ata_pci_device_suspend, 4303b2dec48cSSaeed Bishara .resume = mv_pci_device_resume, 4304b2dec48cSSaeed Bishara #endif 4305b2dec48cSSaeed Bishara 43067bb3c529SSaeed Bishara }; 43077bb3c529SSaeed Bishara 43087bb3c529SSaeed Bishara /* move to PCI layer or libata core? */ 43097bb3c529SSaeed Bishara static int pci_go_64(struct pci_dev *pdev) 43107bb3c529SSaeed Bishara { 43117bb3c529SSaeed Bishara int rc; 43127bb3c529SSaeed Bishara 43136a35528aSYang Hongyang if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { 43146a35528aSYang Hongyang rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 43157bb3c529SSaeed Bishara if (rc) { 4316284901a9SYang Hongyang rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 43177bb3c529SSaeed Bishara if (rc) { 4318a44fec1fSJoe Perches dev_err(&pdev->dev, 43197bb3c529SSaeed Bishara "64-bit DMA enable failed\n"); 43207bb3c529SSaeed Bishara return rc; 43217bb3c529SSaeed Bishara } 43227bb3c529SSaeed Bishara } 43237bb3c529SSaeed Bishara } else { 4324284901a9SYang Hongyang rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 43257bb3c529SSaeed Bishara if (rc) { 4326a44fec1fSJoe Perches dev_err(&pdev->dev, "32-bit DMA enable failed\n"); 43277bb3c529SSaeed Bishara return rc; 43287bb3c529SSaeed Bishara } 4329284901a9SYang Hongyang rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 43307bb3c529SSaeed Bishara if (rc) { 4331a44fec1fSJoe Perches dev_err(&pdev->dev, 43327bb3c529SSaeed Bishara "32-bit consistent DMA enable failed\n"); 43337bb3c529SSaeed Bishara return rc; 43347bb3c529SSaeed Bishara } 43357bb3c529SSaeed Bishara } 43367bb3c529SSaeed Bishara 43377bb3c529SSaeed Bishara return rc; 43387bb3c529SSaeed Bishara } 43397bb3c529SSaeed Bishara 4340c6fd2807SJeff Garzik /** 4341c6fd2807SJeff Garzik * mv_print_info - Dump key info to kernel log for perusal. 43424447d351STejun Heo * @host: ATA host to print info about 4343c6fd2807SJeff Garzik * 4344c6fd2807SJeff Garzik * FIXME: complete this. 4345c6fd2807SJeff Garzik * 4346c6fd2807SJeff Garzik * LOCKING: 4347c6fd2807SJeff Garzik * Inherited from caller. 4348c6fd2807SJeff Garzik */ 43494447d351STejun Heo static void mv_print_info(struct ata_host *host) 4350c6fd2807SJeff Garzik { 43514447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 43524447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 435344c10138SAuke Kok u8 scc; 4354c1e4fe71SJeff Garzik const char *scc_s, *gen; 4355c6fd2807SJeff Garzik 4356c6fd2807SJeff Garzik /* Use this to determine the HW stepping of the chip so we know 4357c6fd2807SJeff Garzik * what errata to workaround 4358c6fd2807SJeff Garzik */ 4359c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc); 4360c6fd2807SJeff Garzik if (scc == 0) 4361c6fd2807SJeff Garzik scc_s = "SCSI"; 4362c6fd2807SJeff Garzik else if (scc == 0x01) 4363c6fd2807SJeff Garzik scc_s = "RAID"; 4364c6fd2807SJeff Garzik else 4365c1e4fe71SJeff Garzik scc_s = "?"; 4366c1e4fe71SJeff Garzik 4367c1e4fe71SJeff Garzik if (IS_GEN_I(hpriv)) 4368c1e4fe71SJeff Garzik gen = "I"; 4369c1e4fe71SJeff Garzik else if (IS_GEN_II(hpriv)) 4370c1e4fe71SJeff Garzik gen = "II"; 4371c1e4fe71SJeff Garzik else if (IS_GEN_IIE(hpriv)) 4372c1e4fe71SJeff Garzik gen = "IIE"; 4373c1e4fe71SJeff Garzik else 4374c1e4fe71SJeff Garzik gen = "?"; 4375c6fd2807SJeff Garzik 4376a44fec1fSJoe Perches dev_info(&pdev->dev, "Gen-%s %u slots %u ports %s mode IRQ via %s\n", 4377c1e4fe71SJeff Garzik gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports, 4378c6fd2807SJeff Garzik scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 4379c6fd2807SJeff Garzik } 4380c6fd2807SJeff Garzik 4381c6fd2807SJeff Garzik /** 4382f351b2d6SSaeed Bishara * mv_pci_init_one - handle a positive probe of a PCI Marvell host 4383c6fd2807SJeff Garzik * @pdev: PCI device found 4384c6fd2807SJeff Garzik * @ent: PCI device ID entry for the matched host 4385c6fd2807SJeff Garzik * 4386c6fd2807SJeff Garzik * LOCKING: 4387c6fd2807SJeff Garzik * Inherited from caller. 4388c6fd2807SJeff Garzik */ 4389f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 4390f351b2d6SSaeed Bishara const struct pci_device_id *ent) 4391c6fd2807SJeff Garzik { 4392c6fd2807SJeff Garzik unsigned int board_idx = (unsigned int)ent->driver_data; 43934447d351STejun Heo const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL }; 43944447d351STejun Heo struct ata_host *host; 43954447d351STejun Heo struct mv_host_priv *hpriv; 4396c4bc7d73SSaeed Bishara int n_ports, port, rc; 4397c6fd2807SJeff Garzik 439806296a1eSJoe Perches ata_print_version_once(&pdev->dev, DRV_VERSION); 4399c6fd2807SJeff Garzik 44004447d351STejun Heo /* allocate host */ 44014447d351STejun Heo n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC; 44024447d351STejun Heo 44034447d351STejun Heo host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 44044447d351STejun Heo hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 44054447d351STejun Heo if (!host || !hpriv) 44064447d351STejun Heo return -ENOMEM; 44074447d351STejun Heo host->private_data = hpriv; 4408f351b2d6SSaeed Bishara hpriv->n_ports = n_ports; 44091bfeff03SSaeed Bishara hpriv->board_idx = board_idx; 44104447d351STejun Heo 44114447d351STejun Heo /* acquire resources */ 441224dc5f33STejun Heo rc = pcim_enable_device(pdev); 441324dc5f33STejun Heo if (rc) 4414c6fd2807SJeff Garzik return rc; 4415c6fd2807SJeff Garzik 44160d5ff566STejun Heo rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 44170d5ff566STejun Heo if (rc == -EBUSY) 441824dc5f33STejun Heo pcim_pin_device(pdev); 44190d5ff566STejun Heo if (rc) 442024dc5f33STejun Heo return rc; 44214447d351STejun Heo host->iomap = pcim_iomap_table(pdev); 4422f351b2d6SSaeed Bishara hpriv->base = host->iomap[MV_PRIMARY_BAR]; 4423c6fd2807SJeff Garzik 4424d88184fbSJeff Garzik rc = pci_go_64(pdev); 4425d88184fbSJeff Garzik if (rc) 4426d88184fbSJeff Garzik return rc; 4427d88184fbSJeff Garzik 4428da2fa9baSMark Lord rc = mv_create_dma_pools(hpriv, &pdev->dev); 4429da2fa9baSMark Lord if (rc) 4430da2fa9baSMark Lord return rc; 4431da2fa9baSMark Lord 4432c4bc7d73SSaeed Bishara for (port = 0; port < host->n_ports; port++) { 4433c4bc7d73SSaeed Bishara struct ata_port *ap = host->ports[port]; 4434c4bc7d73SSaeed Bishara void __iomem *port_mmio = mv_port_base(hpriv->base, port); 4435c4bc7d73SSaeed Bishara unsigned int offset = port_mmio - hpriv->base; 4436c4bc7d73SSaeed Bishara 4437c4bc7d73SSaeed Bishara ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio"); 4438c4bc7d73SSaeed Bishara ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port"); 4439c4bc7d73SSaeed Bishara } 4440c4bc7d73SSaeed Bishara 4441c6fd2807SJeff Garzik /* initialize adapter */ 44421bfeff03SSaeed Bishara rc = mv_init_host(host); 444324dc5f33STejun Heo if (rc) 444424dc5f33STejun Heo return rc; 4445c6fd2807SJeff Garzik 44466d3c30efSMark Lord /* Enable message-switched interrupts, if requested */ 44476d3c30efSMark Lord if (msi && pci_enable_msi(pdev) == 0) 44486d3c30efSMark Lord hpriv->hp_flags |= MV_HP_FLAG_MSI; 4449c6fd2807SJeff Garzik 4450c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 44514447d351STejun Heo mv_print_info(host); 4452c6fd2807SJeff Garzik 44534447d351STejun Heo pci_set_master(pdev); 4454ea8b4db9SJeff Garzik pci_try_set_mwi(pdev); 44554447d351STejun Heo return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, 4456c5d3e45aSJeff Garzik IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht); 4457c6fd2807SJeff Garzik } 4458b2dec48cSSaeed Bishara 4459b2dec48cSSaeed Bishara #ifdef CONFIG_PM 4460b2dec48cSSaeed Bishara static int mv_pci_device_resume(struct pci_dev *pdev) 4461b2dec48cSSaeed Bishara { 4462d8661921SSergei Shtylyov struct ata_host *host = pci_get_drvdata(pdev); 4463b2dec48cSSaeed Bishara int rc; 4464b2dec48cSSaeed Bishara 4465b2dec48cSSaeed Bishara rc = ata_pci_device_do_resume(pdev); 4466b2dec48cSSaeed Bishara if (rc) 4467b2dec48cSSaeed Bishara return rc; 4468b2dec48cSSaeed Bishara 4469b2dec48cSSaeed Bishara /* initialize adapter */ 4470b2dec48cSSaeed Bishara rc = mv_init_host(host); 4471b2dec48cSSaeed Bishara if (rc) 4472b2dec48cSSaeed Bishara return rc; 4473b2dec48cSSaeed Bishara 4474b2dec48cSSaeed Bishara ata_host_resume(host); 4475b2dec48cSSaeed Bishara 4476b2dec48cSSaeed Bishara return 0; 4477b2dec48cSSaeed Bishara } 4478b2dec48cSSaeed Bishara #endif 44797bb3c529SSaeed Bishara #endif 4480c6fd2807SJeff Garzik 4481c6fd2807SJeff Garzik static int __init mv_init(void) 4482c6fd2807SJeff Garzik { 44837bb3c529SSaeed Bishara int rc = -ENODEV; 44847bb3c529SSaeed Bishara #ifdef CONFIG_PCI 44857bb3c529SSaeed Bishara rc = pci_register_driver(&mv_pci_driver); 4486f351b2d6SSaeed Bishara if (rc < 0) 4487f351b2d6SSaeed Bishara return rc; 4488f351b2d6SSaeed Bishara #endif 4489f351b2d6SSaeed Bishara rc = platform_driver_register(&mv_platform_driver); 4490f351b2d6SSaeed Bishara 4491f351b2d6SSaeed Bishara #ifdef CONFIG_PCI 4492f351b2d6SSaeed Bishara if (rc < 0) 4493f351b2d6SSaeed Bishara pci_unregister_driver(&mv_pci_driver); 44947bb3c529SSaeed Bishara #endif 44957bb3c529SSaeed Bishara return rc; 4496c6fd2807SJeff Garzik } 4497c6fd2807SJeff Garzik 4498c6fd2807SJeff Garzik static void __exit mv_exit(void) 4499c6fd2807SJeff Garzik { 45007bb3c529SSaeed Bishara #ifdef CONFIG_PCI 4501c6fd2807SJeff Garzik pci_unregister_driver(&mv_pci_driver); 45027bb3c529SSaeed Bishara #endif 4503f351b2d6SSaeed Bishara platform_driver_unregister(&mv_platform_driver); 4504c6fd2807SJeff Garzik } 4505c6fd2807SJeff Garzik 4506c6fd2807SJeff Garzik MODULE_AUTHOR("Brett Russ"); 4507c6fd2807SJeff Garzik MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers"); 4508c6fd2807SJeff Garzik MODULE_LICENSE("GPL"); 4509c6fd2807SJeff Garzik MODULE_DEVICE_TABLE(pci, mv_pci_tbl); 4510c6fd2807SJeff Garzik MODULE_VERSION(DRV_VERSION); 451117c5aab5SMark Lord MODULE_ALIAS("platform:" DRV_NAME); 4512c6fd2807SJeff Garzik 4513c6fd2807SJeff Garzik module_init(mv_init); 4514c6fd2807SJeff Garzik module_exit(mv_exit); 4515