1c6fd2807SJeff Garzik /* 2c6fd2807SJeff Garzik * sata_mv.c - Marvell SATA support 3c6fd2807SJeff Garzik * 4c6fd2807SJeff Garzik * Copyright 2005: EMC Corporation, all rights reserved. 5c6fd2807SJeff Garzik * Copyright 2005 Red Hat, Inc. All rights reserved. 6c6fd2807SJeff Garzik * 7c6fd2807SJeff Garzik * Please ALWAYS copy linux-ide@vger.kernel.org on emails. 8c6fd2807SJeff Garzik * 9c6fd2807SJeff Garzik * This program is free software; you can redistribute it and/or modify 10c6fd2807SJeff Garzik * it under the terms of the GNU General Public License as published by 11c6fd2807SJeff Garzik * the Free Software Foundation; version 2 of the License. 12c6fd2807SJeff Garzik * 13c6fd2807SJeff Garzik * This program is distributed in the hope that it will be useful, 14c6fd2807SJeff Garzik * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c6fd2807SJeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c6fd2807SJeff Garzik * GNU General Public License for more details. 17c6fd2807SJeff Garzik * 18c6fd2807SJeff Garzik * You should have received a copy of the GNU General Public License 19c6fd2807SJeff Garzik * along with this program; if not, write to the Free Software 20c6fd2807SJeff Garzik * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c6fd2807SJeff Garzik * 22c6fd2807SJeff Garzik */ 23c6fd2807SJeff Garzik 244a05e209SJeff Garzik /* 254a05e209SJeff Garzik sata_mv TODO list: 264a05e209SJeff Garzik 274a05e209SJeff Garzik 1) Needs a full errata audit for all chipsets. I implemented most 284a05e209SJeff Garzik of the errata workarounds found in the Marvell vendor driver, but 294a05e209SJeff Garzik I distinctly remember a couple workarounds (one related to PCI-X) 304a05e209SJeff Garzik are still needed. 314a05e209SJeff Garzik 321fd2e1c2SMark Lord 2) Improve/fix IRQ and error handling sequences. 331fd2e1c2SMark Lord 341fd2e1c2SMark Lord 3) ATAPI support (Marvell claims the 60xx/70xx chips can do it). 351fd2e1c2SMark Lord 361fd2e1c2SMark Lord 4) Think about TCQ support here, and for libata in general 371fd2e1c2SMark Lord with controllers that suppport it via host-queuing hardware 381fd2e1c2SMark Lord (a software-only implementation could be a nightmare). 394a05e209SJeff Garzik 404a05e209SJeff Garzik 5) Investigate problems with PCI Message Signalled Interrupts (MSI). 414a05e209SJeff Garzik 424a05e209SJeff Garzik 6) Add port multiplier support (intermediate) 434a05e209SJeff Garzik 444a05e209SJeff Garzik 8) Develop a low-power-consumption strategy, and implement it. 454a05e209SJeff Garzik 464a05e209SJeff Garzik 9) [Experiment, low priority] See if ATAPI can be supported using 474a05e209SJeff Garzik "unknown FIS" or "vendor-specific FIS" support, or something creative 484a05e209SJeff Garzik like that. 494a05e209SJeff Garzik 504a05e209SJeff Garzik 10) [Experiment, low priority] Investigate interrupt coalescing. 514a05e209SJeff Garzik Quite often, especially with PCI Message Signalled Interrupts (MSI), 524a05e209SJeff Garzik the overhead reduced by interrupt mitigation is quite often not 534a05e209SJeff Garzik worth the latency cost. 544a05e209SJeff Garzik 554a05e209SJeff Garzik 11) [Experiment, Marvell value added] Is it possible to use target 564a05e209SJeff Garzik mode to cross-connect two Linux boxes with Marvell cards? If so, 574a05e209SJeff Garzik creating LibATA target mode support would be very interesting. 584a05e209SJeff Garzik 594a05e209SJeff Garzik Target mode, for those without docs, is the ability to directly 604a05e209SJeff Garzik connect two SATA controllers. 614a05e209SJeff Garzik 624a05e209SJeff Garzik */ 634a05e209SJeff Garzik 644a05e209SJeff Garzik 65c6fd2807SJeff Garzik #include <linux/kernel.h> 66c6fd2807SJeff Garzik #include <linux/module.h> 67c6fd2807SJeff Garzik #include <linux/pci.h> 68c6fd2807SJeff Garzik #include <linux/init.h> 69c6fd2807SJeff Garzik #include <linux/blkdev.h> 70c6fd2807SJeff Garzik #include <linux/delay.h> 71c6fd2807SJeff Garzik #include <linux/interrupt.h> 728d8b6004SAndrew Morton #include <linux/dmapool.h> 73c6fd2807SJeff Garzik #include <linux/dma-mapping.h> 74c6fd2807SJeff Garzik #include <linux/device.h> 75f351b2d6SSaeed Bishara #include <linux/platform_device.h> 76f351b2d6SSaeed Bishara #include <linux/ata_platform.h> 77c6fd2807SJeff Garzik #include <scsi/scsi_host.h> 78c6fd2807SJeff Garzik #include <scsi/scsi_cmnd.h> 796c08772eSJeff Garzik #include <scsi/scsi_device.h> 80c6fd2807SJeff Garzik #include <linux/libata.h> 81c6fd2807SJeff Garzik 82c6fd2807SJeff Garzik #define DRV_NAME "sata_mv" 831fd2e1c2SMark Lord #define DRV_VERSION "1.20" 84c6fd2807SJeff Garzik 85c6fd2807SJeff Garzik enum { 86c6fd2807SJeff Garzik /* BAR's are enumerated in terms of pci_resource_start() terms */ 87c6fd2807SJeff Garzik MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */ 88c6fd2807SJeff Garzik MV_IO_BAR = 2, /* offset 0x18: IO space */ 89c6fd2807SJeff Garzik MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */ 90c6fd2807SJeff Garzik 91c6fd2807SJeff Garzik MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */ 92c6fd2807SJeff Garzik MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */ 93c6fd2807SJeff Garzik 94c6fd2807SJeff Garzik MV_PCI_REG_BASE = 0, 95c6fd2807SJeff Garzik MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ 96c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08), 97c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88), 98c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c), 99c6fd2807SJeff Garzik MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc), 100c6fd2807SJeff Garzik MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0), 101c6fd2807SJeff Garzik 102c6fd2807SJeff Garzik MV_SATAHC0_REG_BASE = 0x20000, 103c6fd2807SJeff Garzik MV_FLASH_CTL = 0x1046c, 104c6fd2807SJeff Garzik MV_GPIO_PORT_CTL = 0x104f0, 105c6fd2807SJeff Garzik MV_RESET_CFG = 0x180d8, 106c6fd2807SJeff Garzik 107c6fd2807SJeff Garzik MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, 108c6fd2807SJeff Garzik MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, 109c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 110c6fd2807SJeff Garzik MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 111c6fd2807SJeff Garzik 112c6fd2807SJeff Garzik MV_MAX_Q_DEPTH = 32, 113c6fd2807SJeff Garzik MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, 114c6fd2807SJeff Garzik 115c6fd2807SJeff Garzik /* CRQB needs alignment on a 1KB boundary. Size == 1KB 116c6fd2807SJeff Garzik * CRPB needs alignment on a 256B boundary. Size == 256B 117c6fd2807SJeff Garzik * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B 118c6fd2807SJeff Garzik */ 119c6fd2807SJeff Garzik MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH), 120c6fd2807SJeff Garzik MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH), 121da2fa9baSMark Lord MV_MAX_SG_CT = 256, 122c6fd2807SJeff Garzik MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), 123c6fd2807SJeff Garzik 124c6fd2807SJeff Garzik MV_PORTS_PER_HC = 4, 125c6fd2807SJeff Garzik /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ 126c6fd2807SJeff Garzik MV_PORT_HC_SHIFT = 2, 127c6fd2807SJeff Garzik /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */ 128c6fd2807SJeff Garzik MV_PORT_MASK = 3, 129c6fd2807SJeff Garzik 130c6fd2807SJeff Garzik /* Host Flags */ 131c6fd2807SJeff Garzik MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 132c6fd2807SJeff Garzik MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 1337bb3c529SSaeed Bishara /* SoC integrated controllers, no PCI interface */ 1347bb3c529SSaeed Bishara MV_FLAG_SOC = (1 << 28), 1357bb3c529SSaeed Bishara 136c5d3e45aSJeff Garzik MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 137bdd4dddeSJeff Garzik ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | 138bdd4dddeSJeff Garzik ATA_FLAG_PIO_POLLING, 139c6fd2807SJeff Garzik MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 140c6fd2807SJeff Garzik 141c6fd2807SJeff Garzik CRQB_FLAG_READ = (1 << 0), 142c6fd2807SJeff Garzik CRQB_TAG_SHIFT = 1, 143c5d3e45aSJeff Garzik CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */ 144c5d3e45aSJeff Garzik CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */ 145c6fd2807SJeff Garzik CRQB_CMD_ADDR_SHIFT = 8, 146c6fd2807SJeff Garzik CRQB_CMD_CS = (0x2 << 11), 147c6fd2807SJeff Garzik CRQB_CMD_LAST = (1 << 15), 148c6fd2807SJeff Garzik 149c6fd2807SJeff Garzik CRPB_FLAG_STATUS_SHIFT = 8, 150c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */ 151c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */ 152c6fd2807SJeff Garzik 153c6fd2807SJeff Garzik EPRD_FLAG_END_OF_TBL = (1 << 31), 154c6fd2807SJeff Garzik 155c6fd2807SJeff Garzik /* PCI interface registers */ 156c6fd2807SJeff Garzik 157c6fd2807SJeff Garzik PCI_COMMAND_OFS = 0xc00, 158c6fd2807SJeff Garzik 159c6fd2807SJeff Garzik PCI_MAIN_CMD_STS_OFS = 0xd30, 160c6fd2807SJeff Garzik STOP_PCI_MASTER = (1 << 2), 161c6fd2807SJeff Garzik PCI_MASTER_EMPTY = (1 << 3), 162c6fd2807SJeff Garzik GLOB_SFT_RST = (1 << 4), 163c6fd2807SJeff Garzik 164c6fd2807SJeff Garzik MV_PCI_MODE = 0xd00, 165c6fd2807SJeff Garzik MV_PCI_EXP_ROM_BAR_CTL = 0xd2c, 166c6fd2807SJeff Garzik MV_PCI_DISC_TIMER = 0xd04, 167c6fd2807SJeff Garzik MV_PCI_MSI_TRIGGER = 0xc38, 168c6fd2807SJeff Garzik MV_PCI_SERR_MASK = 0xc28, 169c6fd2807SJeff Garzik MV_PCI_XBAR_TMOUT = 0x1d04, 170c6fd2807SJeff Garzik MV_PCI_ERR_LOW_ADDRESS = 0x1d40, 171c6fd2807SJeff Garzik MV_PCI_ERR_HIGH_ADDRESS = 0x1d44, 172c6fd2807SJeff Garzik MV_PCI_ERR_ATTRIBUTE = 0x1d48, 173c6fd2807SJeff Garzik MV_PCI_ERR_COMMAND = 0x1d50, 174c6fd2807SJeff Garzik 175c6fd2807SJeff Garzik PCI_IRQ_CAUSE_OFS = 0x1d58, 176c6fd2807SJeff Garzik PCI_IRQ_MASK_OFS = 0x1d5c, 177c6fd2807SJeff Garzik PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ 178c6fd2807SJeff Garzik 17902a121daSMark Lord PCIE_IRQ_CAUSE_OFS = 0x1900, 18002a121daSMark Lord PCIE_IRQ_MASK_OFS = 0x1910, 181646a4da5SMark Lord PCIE_UNMASK_ALL_IRQS = 0x40a, /* assorted bits */ 18202a121daSMark Lord 183c6fd2807SJeff Garzik HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, 184c6fd2807SJeff Garzik HC_MAIN_IRQ_MASK_OFS = 0x1d64, 185f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_CAUSE_OFS = 0x20020, 186f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_MASK_OFS = 0x20024, 187c6fd2807SJeff Garzik PORT0_ERR = (1 << 0), /* shift by port # */ 188c6fd2807SJeff Garzik PORT0_DONE = (1 << 1), /* shift by port # */ 189c6fd2807SJeff Garzik HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 190c6fd2807SJeff Garzik HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 191c6fd2807SJeff Garzik PCI_ERR = (1 << 18), 192c6fd2807SJeff Garzik TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */ 193c6fd2807SJeff Garzik TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */ 194fb621e2fSJeff Garzik PORTS_0_3_COAL_DONE = (1 << 8), 195fb621e2fSJeff Garzik PORTS_4_7_COAL_DONE = (1 << 17), 196c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */ 197c6fd2807SJeff Garzik GPIO_INT = (1 << 22), 198c6fd2807SJeff Garzik SELF_INT = (1 << 23), 199c6fd2807SJeff Garzik TWSI_INT = (1 << 24), 200c6fd2807SJeff Garzik HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ 201fb621e2fSJeff Garzik HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */ 202f351b2d6SSaeed Bishara HC_MAIN_RSVD_SOC = (0x3fffffb << 6), /* bits 31-9, 7-6 */ 203c6fd2807SJeff Garzik HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | 204c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | 205c6fd2807SJeff Garzik HC_MAIN_RSVD), 206fb621e2fSJeff Garzik HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE | 207fb621e2fSJeff Garzik HC_MAIN_RSVD_5), 208f351b2d6SSaeed Bishara HC_MAIN_MASKED_IRQS_SOC = (PORTS_0_3_COAL_DONE | HC_MAIN_RSVD_SOC), 209c6fd2807SJeff Garzik 210c6fd2807SJeff Garzik /* SATAHC registers */ 211c6fd2807SJeff Garzik HC_CFG_OFS = 0, 212c6fd2807SJeff Garzik 213c6fd2807SJeff Garzik HC_IRQ_CAUSE_OFS = 0x14, 214c6fd2807SJeff Garzik CRPB_DMA_DONE = (1 << 0), /* shift by port # */ 215c6fd2807SJeff Garzik HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */ 216c6fd2807SJeff Garzik DEV_IRQ = (1 << 8), /* shift by port # */ 217c6fd2807SJeff Garzik 218c6fd2807SJeff Garzik /* Shadow block registers */ 219c6fd2807SJeff Garzik SHD_BLK_OFS = 0x100, 220c6fd2807SJeff Garzik SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */ 221c6fd2807SJeff Garzik 222c6fd2807SJeff Garzik /* SATA registers */ 223c6fd2807SJeff Garzik SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ 224c6fd2807SJeff Garzik SATA_ACTIVE_OFS = 0x350, 2250c58912eSMark Lord SATA_FIS_IRQ_CAUSE_OFS = 0x364, 226c6fd2807SJeff Garzik PHY_MODE3 = 0x310, 227c6fd2807SJeff Garzik PHY_MODE4 = 0x314, 228c6fd2807SJeff Garzik PHY_MODE2 = 0x330, 229c6fd2807SJeff Garzik MV5_PHY_MODE = 0x74, 230c6fd2807SJeff Garzik MV5_LT_MODE = 0x30, 231c6fd2807SJeff Garzik MV5_PHY_CTL = 0x0C, 232c6fd2807SJeff Garzik SATA_INTERFACE_CTL = 0x050, 233c6fd2807SJeff Garzik 234c6fd2807SJeff Garzik MV_M2_PREAMP_MASK = 0x7e0, 235c6fd2807SJeff Garzik 236c6fd2807SJeff Garzik /* Port registers */ 237c6fd2807SJeff Garzik EDMA_CFG_OFS = 0, 2380c58912eSMark Lord EDMA_CFG_Q_DEPTH = 0x1f, /* max device queue depth */ 2390c58912eSMark Lord EDMA_CFG_NCQ = (1 << 5), /* for R/W FPDMA queued */ 240c6fd2807SJeff Garzik EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */ 241c6fd2807SJeff Garzik EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */ 242c6fd2807SJeff Garzik EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */ 243c6fd2807SJeff Garzik 244c6fd2807SJeff Garzik EDMA_ERR_IRQ_CAUSE_OFS = 0x8, 245c6fd2807SJeff Garzik EDMA_ERR_IRQ_MASK_OFS = 0xc, 2466c1153e0SJeff Garzik EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */ 2476c1153e0SJeff Garzik EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */ 2486c1153e0SJeff Garzik EDMA_ERR_DEV = (1 << 2), /* device error */ 2496c1153e0SJeff Garzik EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */ 2506c1153e0SJeff Garzik EDMA_ERR_DEV_CON = (1 << 4), /* device connected */ 2516c1153e0SJeff Garzik EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */ 252c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ 253c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ 2546c1153e0SJeff Garzik EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */ 255c5d3e45aSJeff Garzik EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ 2566c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */ 2576c1153e0SJeff Garzik EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */ 2586c1153e0SJeff Garzik EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */ 2596c1153e0SJeff Garzik EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */ 260646a4da5SMark Lord 2616c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */ 262646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_0 = (1 << 13), /* transient: CRC err */ 263646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 = (1 << 14), /* transient: FIFO err */ 264646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), /* fatal: caught SYNC */ 265646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 = (1 << 16), /* transient: FIS rx err */ 266646a4da5SMark Lord 2676c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */ 268646a4da5SMark Lord 2696c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */ 270646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_0 = (1 << 21), /* transient: CRC err */ 271646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_1 = (1 << 22), /* transient: FIFO err */ 272646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_2 = (1 << 23), /* transient: caught SYNC */ 273646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_3 = (1 << 24), /* transient: caught DMAT */ 274646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_4 = (1 << 25), /* transient: FIS collision */ 275646a4da5SMark Lord 2766c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */ 277646a4da5SMark Lord 2786c1153e0SJeff Garzik EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */ 279c5d3e45aSJeff Garzik EDMA_ERR_OVERRUN_5 = (1 << 5), 280c5d3e45aSJeff Garzik EDMA_ERR_UNDERRUN_5 = (1 << 6), 281646a4da5SMark Lord 282646a4da5SMark Lord EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 | 283646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 | 284646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 | 285646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX, 286646a4da5SMark Lord 287bdd4dddeSJeff Garzik EDMA_EH_FREEZE = EDMA_ERR_D_PAR | 288bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 289bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 290bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 291bdd4dddeSJeff Garzik EDMA_ERR_SERR | 292bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS | 2936c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 294bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 295bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 296bdd4dddeSJeff Garzik EDMA_ERR_IORDY | 297bdd4dddeSJeff Garzik EDMA_ERR_LNK_CTRL_RX_2 | 298c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_RX | 299c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_TX | 300bdd4dddeSJeff Garzik EDMA_ERR_TRANS_PROTO, 301bdd4dddeSJeff Garzik EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR | 302bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 303bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 304bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 305bdd4dddeSJeff Garzik EDMA_ERR_OVERRUN_5 | 306bdd4dddeSJeff Garzik EDMA_ERR_UNDERRUN_5 | 307bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS_5 | 3086c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 309bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 310bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 311bdd4dddeSJeff Garzik EDMA_ERR_IORDY, 312c6fd2807SJeff Garzik 313c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_HI_OFS = 0x10, 314c6fd2807SJeff Garzik EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ 315c6fd2807SJeff Garzik 316c6fd2807SJeff Garzik EDMA_REQ_Q_OUT_PTR_OFS = 0x18, 317c6fd2807SJeff Garzik EDMA_REQ_Q_PTR_SHIFT = 5, 318c6fd2807SJeff Garzik 319c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_HI_OFS = 0x1c, 320c6fd2807SJeff Garzik EDMA_RSP_Q_IN_PTR_OFS = 0x20, 321c6fd2807SJeff Garzik EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ 322c6fd2807SJeff Garzik EDMA_RSP_Q_PTR_SHIFT = 3, 323c6fd2807SJeff Garzik 3240ea9e179SJeff Garzik EDMA_CMD_OFS = 0x28, /* EDMA command register */ 3250ea9e179SJeff Garzik EDMA_EN = (1 << 0), /* enable EDMA */ 3260ea9e179SJeff Garzik EDMA_DS = (1 << 1), /* disable EDMA; self-negated */ 3270ea9e179SJeff Garzik ATA_RST = (1 << 2), /* reset trans/link/phy */ 328c6fd2807SJeff Garzik 329c6fd2807SJeff Garzik EDMA_IORDY_TMOUT = 0x34, 330c6fd2807SJeff Garzik EDMA_ARB_CFG = 0x38, 331c6fd2807SJeff Garzik 332c6fd2807SJeff Garzik /* Host private flags (hp_flags) */ 333c6fd2807SJeff Garzik MV_HP_FLAG_MSI = (1 << 0), 334c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB0 = (1 << 1), 335c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB2 = (1 << 2), 336c6fd2807SJeff Garzik MV_HP_ERRATA_60X1B2 = (1 << 3), 337c6fd2807SJeff Garzik MV_HP_ERRATA_60X1C0 = (1 << 4), 338c6fd2807SJeff Garzik MV_HP_ERRATA_XX42A0 = (1 << 5), 3390ea9e179SJeff Garzik MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */ 3400ea9e179SJeff Garzik MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */ 3410ea9e179SJeff Garzik MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */ 34202a121daSMark Lord MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */ 343c6fd2807SJeff Garzik 344c6fd2807SJeff Garzik /* Port private flags (pp_flags) */ 3450ea9e179SJeff Garzik MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ 34672109168SMark Lord MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */ 3470ea9e179SJeff Garzik MV_PP_FLAG_HAD_A_RESET = (1 << 2), /* 1st hard reset complete? */ 348c6fd2807SJeff Garzik }; 349c6fd2807SJeff Garzik 350ee9ccdf7SJeff Garzik #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) 351ee9ccdf7SJeff Garzik #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II) 352c6fd2807SJeff Garzik #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 3537bb3c529SSaeed Bishara #define HAS_PCI(host) (!((host)->ports[0]->flags & MV_FLAG_SOC)) 354c6fd2807SJeff Garzik 355c6fd2807SJeff Garzik enum { 356baf14aa1SJeff Garzik /* DMA boundary 0xffff is required by the s/g splitting 357baf14aa1SJeff Garzik * we need on /length/ in mv_fill-sg(). 358baf14aa1SJeff Garzik */ 359baf14aa1SJeff Garzik MV_DMA_BOUNDARY = 0xffffU, 360c6fd2807SJeff Garzik 3610ea9e179SJeff Garzik /* mask of register bits containing lower 32 bits 3620ea9e179SJeff Garzik * of EDMA request queue DMA address 3630ea9e179SJeff Garzik */ 364c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 365c6fd2807SJeff Garzik 3660ea9e179SJeff Garzik /* ditto, for response queue */ 367c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, 368c6fd2807SJeff Garzik }; 369c6fd2807SJeff Garzik 370c6fd2807SJeff Garzik enum chip_type { 371c6fd2807SJeff Garzik chip_504x, 372c6fd2807SJeff Garzik chip_508x, 373c6fd2807SJeff Garzik chip_5080, 374c6fd2807SJeff Garzik chip_604x, 375c6fd2807SJeff Garzik chip_608x, 376c6fd2807SJeff Garzik chip_6042, 377c6fd2807SJeff Garzik chip_7042, 378f351b2d6SSaeed Bishara chip_soc, 379c6fd2807SJeff Garzik }; 380c6fd2807SJeff Garzik 381c6fd2807SJeff Garzik /* Command ReQuest Block: 32B */ 382c6fd2807SJeff Garzik struct mv_crqb { 383c6fd2807SJeff Garzik __le32 sg_addr; 384c6fd2807SJeff Garzik __le32 sg_addr_hi; 385c6fd2807SJeff Garzik __le16 ctrl_flags; 386c6fd2807SJeff Garzik __le16 ata_cmd[11]; 387c6fd2807SJeff Garzik }; 388c6fd2807SJeff Garzik 389c6fd2807SJeff Garzik struct mv_crqb_iie { 390c6fd2807SJeff Garzik __le32 addr; 391c6fd2807SJeff Garzik __le32 addr_hi; 392c6fd2807SJeff Garzik __le32 flags; 393c6fd2807SJeff Garzik __le32 len; 394c6fd2807SJeff Garzik __le32 ata_cmd[4]; 395c6fd2807SJeff Garzik }; 396c6fd2807SJeff Garzik 397c6fd2807SJeff Garzik /* Command ResPonse Block: 8B */ 398c6fd2807SJeff Garzik struct mv_crpb { 399c6fd2807SJeff Garzik __le16 id; 400c6fd2807SJeff Garzik __le16 flags; 401c6fd2807SJeff Garzik __le32 tmstmp; 402c6fd2807SJeff Garzik }; 403c6fd2807SJeff Garzik 404c6fd2807SJeff Garzik /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */ 405c6fd2807SJeff Garzik struct mv_sg { 406c6fd2807SJeff Garzik __le32 addr; 407c6fd2807SJeff Garzik __le32 flags_size; 408c6fd2807SJeff Garzik __le32 addr_hi; 409c6fd2807SJeff Garzik __le32 reserved; 410c6fd2807SJeff Garzik }; 411c6fd2807SJeff Garzik 412c6fd2807SJeff Garzik struct mv_port_priv { 413c6fd2807SJeff Garzik struct mv_crqb *crqb; 414c6fd2807SJeff Garzik dma_addr_t crqb_dma; 415c6fd2807SJeff Garzik struct mv_crpb *crpb; 416c6fd2807SJeff Garzik dma_addr_t crpb_dma; 417eb73d558SMark Lord struct mv_sg *sg_tbl[MV_MAX_Q_DEPTH]; 418eb73d558SMark Lord dma_addr_t sg_tbl_dma[MV_MAX_Q_DEPTH]; 419bdd4dddeSJeff Garzik 420bdd4dddeSJeff Garzik unsigned int req_idx; 421bdd4dddeSJeff Garzik unsigned int resp_idx; 422bdd4dddeSJeff Garzik 423c6fd2807SJeff Garzik u32 pp_flags; 424c6fd2807SJeff Garzik }; 425c6fd2807SJeff Garzik 426c6fd2807SJeff Garzik struct mv_port_signal { 427c6fd2807SJeff Garzik u32 amps; 428c6fd2807SJeff Garzik u32 pre; 429c6fd2807SJeff Garzik }; 430c6fd2807SJeff Garzik 43102a121daSMark Lord struct mv_host_priv { 43202a121daSMark Lord u32 hp_flags; 43302a121daSMark Lord struct mv_port_signal signal[8]; 43402a121daSMark Lord const struct mv_hw_ops *ops; 435f351b2d6SSaeed Bishara int n_ports; 436f351b2d6SSaeed Bishara void __iomem *base; 437f351b2d6SSaeed Bishara void __iomem *main_cause_reg_addr; 438f351b2d6SSaeed Bishara void __iomem *main_mask_reg_addr; 43902a121daSMark Lord u32 irq_cause_ofs; 44002a121daSMark Lord u32 irq_mask_ofs; 44102a121daSMark Lord u32 unmask_all_irqs; 442da2fa9baSMark Lord /* 443da2fa9baSMark Lord * These consistent DMA memory pools give us guaranteed 444da2fa9baSMark Lord * alignment for hardware-accessed data structures, 445da2fa9baSMark Lord * and less memory waste in accomplishing the alignment. 446da2fa9baSMark Lord */ 447da2fa9baSMark Lord struct dma_pool *crqb_pool; 448da2fa9baSMark Lord struct dma_pool *crpb_pool; 449da2fa9baSMark Lord struct dma_pool *sg_tbl_pool; 45002a121daSMark Lord }; 45102a121daSMark Lord 452c6fd2807SJeff Garzik struct mv_hw_ops { 453c6fd2807SJeff Garzik void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, 454c6fd2807SJeff Garzik unsigned int port); 455c6fd2807SJeff Garzik void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio); 456c6fd2807SJeff Garzik void (*read_preamp)(struct mv_host_priv *hpriv, int idx, 457c6fd2807SJeff Garzik void __iomem *mmio); 458c6fd2807SJeff Garzik int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio, 459c6fd2807SJeff Garzik unsigned int n_hc); 460c6fd2807SJeff Garzik void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio); 4617bb3c529SSaeed Bishara void (*reset_bus)(struct ata_host *host, void __iomem *mmio); 462c6fd2807SJeff Garzik }; 463c6fd2807SJeff Garzik 464c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap); 465da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 466da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 467da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 468da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 469c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap); 470c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap); 471c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc); 472c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 473c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 474bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap); 475bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap); 476bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap); 477f273827eSMark Lord static void mv6_dev_config(struct ata_device *dev); 478c6fd2807SJeff Garzik 479c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 480c6fd2807SJeff Garzik unsigned int port); 481c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 482c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 483c6fd2807SJeff Garzik void __iomem *mmio); 484c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 485c6fd2807SJeff Garzik unsigned int n_hc); 486c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 4877bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio); 488c6fd2807SJeff Garzik 489c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 490c6fd2807SJeff Garzik unsigned int port); 491c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 492c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 493c6fd2807SJeff Garzik void __iomem *mmio); 494c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 495c6fd2807SJeff Garzik unsigned int n_hc); 496c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 497f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 498f351b2d6SSaeed Bishara void __iomem *mmio); 499f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 500f351b2d6SSaeed Bishara void __iomem *mmio); 501f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 502f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc); 503f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 504f351b2d6SSaeed Bishara void __iomem *mmio); 505f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio); 5067bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio); 507c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 508c6fd2807SJeff Garzik unsigned int port_no); 50972109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 51072109168SMark Lord void __iomem *port_mmio, int want_ncq); 51172109168SMark Lord static int __mv_stop_dma(struct ata_port *ap); 512c6fd2807SJeff Garzik 513eb73d558SMark Lord /* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below 514eb73d558SMark Lord * because we have to allow room for worst case splitting of 515eb73d558SMark Lord * PRDs for 64K boundaries in mv_fill_sg(). 516eb73d558SMark Lord */ 517c5d3e45aSJeff Garzik static struct scsi_host_template mv5_sht = { 518c6fd2807SJeff Garzik .module = THIS_MODULE, 519c6fd2807SJeff Garzik .name = DRV_NAME, 520c6fd2807SJeff Garzik .ioctl = ata_scsi_ioctl, 521c6fd2807SJeff Garzik .queuecommand = ata_scsi_queuecmd, 522c5d3e45aSJeff Garzik .can_queue = ATA_DEF_QUEUE, 523c5d3e45aSJeff Garzik .this_id = ATA_SHT_THIS_ID, 524baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 525c5d3e45aSJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 526c5d3e45aSJeff Garzik .emulated = ATA_SHT_EMULATED, 527c5d3e45aSJeff Garzik .use_clustering = 1, 528c5d3e45aSJeff Garzik .proc_name = DRV_NAME, 529c5d3e45aSJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 5303be6cbd7SJeff Garzik .slave_configure = ata_scsi_slave_config, 531c5d3e45aSJeff Garzik .slave_destroy = ata_scsi_slave_destroy, 532c5d3e45aSJeff Garzik .bios_param = ata_std_bios_param, 533c5d3e45aSJeff Garzik }; 534c5d3e45aSJeff Garzik 535c5d3e45aSJeff Garzik static struct scsi_host_template mv6_sht = { 536c5d3e45aSJeff Garzik .module = THIS_MODULE, 537c5d3e45aSJeff Garzik .name = DRV_NAME, 538c5d3e45aSJeff Garzik .ioctl = ata_scsi_ioctl, 539c5d3e45aSJeff Garzik .queuecommand = ata_scsi_queuecmd, 540138bfdd0SMark Lord .change_queue_depth = ata_scsi_change_queue_depth, 541138bfdd0SMark Lord .can_queue = MV_MAX_Q_DEPTH - 1, 542c6fd2807SJeff Garzik .this_id = ATA_SHT_THIS_ID, 543baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 544c6fd2807SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 545c6fd2807SJeff Garzik .emulated = ATA_SHT_EMULATED, 546d88184fbSJeff Garzik .use_clustering = 1, 547c6fd2807SJeff Garzik .proc_name = DRV_NAME, 548c6fd2807SJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 5493be6cbd7SJeff Garzik .slave_configure = ata_scsi_slave_config, 550c6fd2807SJeff Garzik .slave_destroy = ata_scsi_slave_destroy, 551c6fd2807SJeff Garzik .bios_param = ata_std_bios_param, 552c6fd2807SJeff Garzik }; 553c6fd2807SJeff Garzik 554c6fd2807SJeff Garzik static const struct ata_port_operations mv5_ops = { 555c6fd2807SJeff Garzik .tf_load = ata_tf_load, 556c6fd2807SJeff Garzik .tf_read = ata_tf_read, 557c6fd2807SJeff Garzik .check_status = ata_check_status, 558c6fd2807SJeff Garzik .exec_command = ata_exec_command, 559c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 560c6fd2807SJeff Garzik 561cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 562c6fd2807SJeff Garzik 563c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 564c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5650d5ff566STejun Heo .data_xfer = ata_data_xfer, 566c6fd2807SJeff Garzik 567c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 568246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 569c6fd2807SJeff Garzik 570bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 571bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 572bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 573bdd4dddeSJeff Garzik 574c6fd2807SJeff Garzik .scr_read = mv5_scr_read, 575c6fd2807SJeff Garzik .scr_write = mv5_scr_write, 576c6fd2807SJeff Garzik 577c6fd2807SJeff Garzik .port_start = mv_port_start, 578c6fd2807SJeff Garzik .port_stop = mv_port_stop, 579c6fd2807SJeff Garzik }; 580c6fd2807SJeff Garzik 581c6fd2807SJeff Garzik static const struct ata_port_operations mv6_ops = { 582f273827eSMark Lord .dev_config = mv6_dev_config, 583c6fd2807SJeff Garzik .tf_load = ata_tf_load, 584c6fd2807SJeff Garzik .tf_read = ata_tf_read, 585c6fd2807SJeff Garzik .check_status = ata_check_status, 586c6fd2807SJeff Garzik .exec_command = ata_exec_command, 587c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 588c6fd2807SJeff Garzik 589cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 590c6fd2807SJeff Garzik 591c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 592c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5930d5ff566STejun Heo .data_xfer = ata_data_xfer, 594c6fd2807SJeff Garzik 595c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 596246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 597c6fd2807SJeff Garzik 598bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 599bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 600bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 601138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 602bdd4dddeSJeff Garzik 603c6fd2807SJeff Garzik .scr_read = mv_scr_read, 604c6fd2807SJeff Garzik .scr_write = mv_scr_write, 605c6fd2807SJeff Garzik 606c6fd2807SJeff Garzik .port_start = mv_port_start, 607c6fd2807SJeff Garzik .port_stop = mv_port_stop, 608c6fd2807SJeff Garzik }; 609c6fd2807SJeff Garzik 610c6fd2807SJeff Garzik static const struct ata_port_operations mv_iie_ops = { 611c6fd2807SJeff Garzik .tf_load = ata_tf_load, 612c6fd2807SJeff Garzik .tf_read = ata_tf_read, 613c6fd2807SJeff Garzik .check_status = ata_check_status, 614c6fd2807SJeff Garzik .exec_command = ata_exec_command, 615c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 616c6fd2807SJeff Garzik 617cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 618c6fd2807SJeff Garzik 619c6fd2807SJeff Garzik .qc_prep = mv_qc_prep_iie, 620c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 6210d5ff566STejun Heo .data_xfer = ata_data_xfer, 622c6fd2807SJeff Garzik 623c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 624246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 625c6fd2807SJeff Garzik 626bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 627bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 628bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 629138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 630bdd4dddeSJeff Garzik 631c6fd2807SJeff Garzik .scr_read = mv_scr_read, 632c6fd2807SJeff Garzik .scr_write = mv_scr_write, 633c6fd2807SJeff Garzik 634c6fd2807SJeff Garzik .port_start = mv_port_start, 635c6fd2807SJeff Garzik .port_stop = mv_port_stop, 636c6fd2807SJeff Garzik }; 637c6fd2807SJeff Garzik 638c6fd2807SJeff Garzik static const struct ata_port_info mv_port_info[] = { 639c6fd2807SJeff Garzik { /* chip_504x */ 640cca3974eSJeff Garzik .flags = MV_COMMON_FLAGS, 641c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 642bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 643c6fd2807SJeff Garzik .port_ops = &mv5_ops, 644c6fd2807SJeff Garzik }, 645c6fd2807SJeff Garzik { /* chip_508x */ 646c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 647c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 648bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 649c6fd2807SJeff Garzik .port_ops = &mv5_ops, 650c6fd2807SJeff Garzik }, 651c6fd2807SJeff Garzik { /* chip_5080 */ 652c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 653c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 654bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 655c6fd2807SJeff Garzik .port_ops = &mv5_ops, 656c6fd2807SJeff Garzik }, 657c6fd2807SJeff Garzik { /* chip_604x */ 658138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 659138bfdd0SMark Lord ATA_FLAG_NCQ, 660c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 661bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 662c6fd2807SJeff Garzik .port_ops = &mv6_ops, 663c6fd2807SJeff Garzik }, 664c6fd2807SJeff Garzik { /* chip_608x */ 665c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 666138bfdd0SMark Lord ATA_FLAG_NCQ | MV_FLAG_DUAL_HC, 667c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 668bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 669c6fd2807SJeff Garzik .port_ops = &mv6_ops, 670c6fd2807SJeff Garzik }, 671c6fd2807SJeff Garzik { /* chip_6042 */ 672138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 673138bfdd0SMark Lord ATA_FLAG_NCQ, 674c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 675bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 676c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 677c6fd2807SJeff Garzik }, 678c6fd2807SJeff Garzik { /* chip_7042 */ 679138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 680138bfdd0SMark Lord ATA_FLAG_NCQ, 681c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 682bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 683c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 684c6fd2807SJeff Garzik }, 685f351b2d6SSaeed Bishara { /* chip_soc */ 686f351b2d6SSaeed Bishara .flags = MV_COMMON_FLAGS | MV_FLAG_SOC, 687f351b2d6SSaeed Bishara .pio_mask = 0x1f, /* pio0-4 */ 688f351b2d6SSaeed Bishara .udma_mask = ATA_UDMA6, 689f351b2d6SSaeed Bishara .port_ops = &mv_iie_ops, 690f351b2d6SSaeed Bishara }, 691c6fd2807SJeff Garzik }; 692c6fd2807SJeff Garzik 693c6fd2807SJeff Garzik static const struct pci_device_id mv_pci_tbl[] = { 6942d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5040), chip_504x }, 6952d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 6962d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 6972d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 698cfbf723eSAlan Cox /* RocketRAID 1740/174x have different identifiers */ 699cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1740), chip_508x }, 700cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1742), chip_508x }, 701c6fd2807SJeff Garzik 7022d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6040), chip_604x }, 7032d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6041), chip_604x }, 7042d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 }, 7052d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6080), chip_608x }, 7062d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6081), chip_608x }, 707c6fd2807SJeff Garzik 7082d2744fcSJeff Garzik { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 7092d2744fcSJeff Garzik 710d9f9c6bcSFlorian Attenberger /* Adaptec 1430SA */ 711d9f9c6bcSFlorian Attenberger { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 }, 712d9f9c6bcSFlorian Attenberger 71302a121daSMark Lord /* Marvell 7042 support */ 7146a3d586dSMorrison, Tom { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 }, 7156a3d586dSMorrison, Tom 71602a121daSMark Lord /* Highpoint RocketRAID PCIe series */ 71702a121daSMark Lord { PCI_VDEVICE(TTI, 0x2300), chip_7042 }, 71802a121daSMark Lord { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 71902a121daSMark Lord 720c6fd2807SJeff Garzik { } /* terminate list */ 721c6fd2807SJeff Garzik }; 722c6fd2807SJeff Garzik 723c6fd2807SJeff Garzik static const struct mv_hw_ops mv5xxx_ops = { 724c6fd2807SJeff Garzik .phy_errata = mv5_phy_errata, 725c6fd2807SJeff Garzik .enable_leds = mv5_enable_leds, 726c6fd2807SJeff Garzik .read_preamp = mv5_read_preamp, 727c6fd2807SJeff Garzik .reset_hc = mv5_reset_hc, 728c6fd2807SJeff Garzik .reset_flash = mv5_reset_flash, 729c6fd2807SJeff Garzik .reset_bus = mv5_reset_bus, 730c6fd2807SJeff Garzik }; 731c6fd2807SJeff Garzik 732c6fd2807SJeff Garzik static const struct mv_hw_ops mv6xxx_ops = { 733c6fd2807SJeff Garzik .phy_errata = mv6_phy_errata, 734c6fd2807SJeff Garzik .enable_leds = mv6_enable_leds, 735c6fd2807SJeff Garzik .read_preamp = mv6_read_preamp, 736c6fd2807SJeff Garzik .reset_hc = mv6_reset_hc, 737c6fd2807SJeff Garzik .reset_flash = mv6_reset_flash, 738c6fd2807SJeff Garzik .reset_bus = mv_reset_pci_bus, 739c6fd2807SJeff Garzik }; 740c6fd2807SJeff Garzik 741f351b2d6SSaeed Bishara static const struct mv_hw_ops mv_soc_ops = { 742f351b2d6SSaeed Bishara .phy_errata = mv6_phy_errata, 743f351b2d6SSaeed Bishara .enable_leds = mv_soc_enable_leds, 744f351b2d6SSaeed Bishara .read_preamp = mv_soc_read_preamp, 745f351b2d6SSaeed Bishara .reset_hc = mv_soc_reset_hc, 746f351b2d6SSaeed Bishara .reset_flash = mv_soc_reset_flash, 747f351b2d6SSaeed Bishara .reset_bus = mv_soc_reset_bus, 748f351b2d6SSaeed Bishara }; 749f351b2d6SSaeed Bishara 750c6fd2807SJeff Garzik /* 751c6fd2807SJeff Garzik * Functions 752c6fd2807SJeff Garzik */ 753c6fd2807SJeff Garzik 754c6fd2807SJeff Garzik static inline void writelfl(unsigned long data, void __iomem *addr) 755c6fd2807SJeff Garzik { 756c6fd2807SJeff Garzik writel(data, addr); 757c6fd2807SJeff Garzik (void) readl(addr); /* flush to avoid PCI posted write */ 758c6fd2807SJeff Garzik } 759c6fd2807SJeff Garzik 760c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) 761c6fd2807SJeff Garzik { 762c6fd2807SJeff Garzik return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 763c6fd2807SJeff Garzik } 764c6fd2807SJeff Garzik 765c6fd2807SJeff Garzik static inline unsigned int mv_hc_from_port(unsigned int port) 766c6fd2807SJeff Garzik { 767c6fd2807SJeff Garzik return port >> MV_PORT_HC_SHIFT; 768c6fd2807SJeff Garzik } 769c6fd2807SJeff Garzik 770c6fd2807SJeff Garzik static inline unsigned int mv_hardport_from_port(unsigned int port) 771c6fd2807SJeff Garzik { 772c6fd2807SJeff Garzik return port & MV_PORT_MASK; 773c6fd2807SJeff Garzik } 774c6fd2807SJeff Garzik 775c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 776c6fd2807SJeff Garzik unsigned int port) 777c6fd2807SJeff Garzik { 778c6fd2807SJeff Garzik return mv_hc_base(base, mv_hc_from_port(port)); 779c6fd2807SJeff Garzik } 780c6fd2807SJeff Garzik 781c6fd2807SJeff Garzik static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) 782c6fd2807SJeff Garzik { 783c6fd2807SJeff Garzik return mv_hc_base_from_port(base, port) + 784c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ + 785c6fd2807SJeff Garzik (mv_hardport_from_port(port) * MV_PORT_REG_SZ); 786c6fd2807SJeff Garzik } 787c6fd2807SJeff Garzik 788f351b2d6SSaeed Bishara static inline void __iomem *mv_host_base(struct ata_host *host) 789f351b2d6SSaeed Bishara { 790f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 791f351b2d6SSaeed Bishara return hpriv->base; 792f351b2d6SSaeed Bishara } 793f351b2d6SSaeed Bishara 794c6fd2807SJeff Garzik static inline void __iomem *mv_ap_base(struct ata_port *ap) 795c6fd2807SJeff Garzik { 796f351b2d6SSaeed Bishara return mv_port_base(mv_host_base(ap->host), ap->port_no); 797c6fd2807SJeff Garzik } 798c6fd2807SJeff Garzik 799cca3974eSJeff Garzik static inline int mv_get_hc_count(unsigned long port_flags) 800c6fd2807SJeff Garzik { 801cca3974eSJeff Garzik return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 802c6fd2807SJeff Garzik } 803c6fd2807SJeff Garzik 804c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap) 805c6fd2807SJeff Garzik { 806c6fd2807SJeff Garzik } 807c6fd2807SJeff Garzik 808c5d3e45aSJeff Garzik static void mv_set_edma_ptrs(void __iomem *port_mmio, 809c5d3e45aSJeff Garzik struct mv_host_priv *hpriv, 810c5d3e45aSJeff Garzik struct mv_port_priv *pp) 811c5d3e45aSJeff Garzik { 812bdd4dddeSJeff Garzik u32 index; 813bdd4dddeSJeff Garzik 814c5d3e45aSJeff Garzik /* 815c5d3e45aSJeff Garzik * initialize request queue 816c5d3e45aSJeff Garzik */ 817bdd4dddeSJeff Garzik index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 818bdd4dddeSJeff Garzik 819c5d3e45aSJeff Garzik WARN_ON(pp->crqb_dma & 0x3ff); 820c5d3e45aSJeff Garzik writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 821bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index, 822c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 823c5d3e45aSJeff Garzik 824c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 825bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & 0xffffffff) | index, 826c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 827c5d3e45aSJeff Garzik else 828bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 829c5d3e45aSJeff Garzik 830c5d3e45aSJeff Garzik /* 831c5d3e45aSJeff Garzik * initialize response queue 832c5d3e45aSJeff Garzik */ 833bdd4dddeSJeff Garzik index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT; 834bdd4dddeSJeff Garzik 835c5d3e45aSJeff Garzik WARN_ON(pp->crpb_dma & 0xff); 836c5d3e45aSJeff Garzik writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 837c5d3e45aSJeff Garzik 838c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 839bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & 0xffffffff) | index, 840c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 841c5d3e45aSJeff Garzik else 842bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 843c5d3e45aSJeff Garzik 844bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index, 845c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 846c5d3e45aSJeff Garzik } 847c5d3e45aSJeff Garzik 848c6fd2807SJeff Garzik /** 849c6fd2807SJeff Garzik * mv_start_dma - Enable eDMA engine 850c6fd2807SJeff Garzik * @base: port base address 851c6fd2807SJeff Garzik * @pp: port private data 852c6fd2807SJeff Garzik * 853c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 854c6fd2807SJeff Garzik * WARN_ON. 855c6fd2807SJeff Garzik * 856c6fd2807SJeff Garzik * LOCKING: 857c6fd2807SJeff Garzik * Inherited from caller. 858c6fd2807SJeff Garzik */ 8590c58912eSMark Lord static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio, 86072109168SMark Lord struct mv_port_priv *pp, u8 protocol) 861c6fd2807SJeff Garzik { 86272109168SMark Lord int want_ncq = (protocol == ATA_PROT_NCQ); 86372109168SMark Lord 86472109168SMark Lord if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 86572109168SMark Lord int using_ncq = ((pp->pp_flags & MV_PP_FLAG_NCQ_EN) != 0); 86672109168SMark Lord if (want_ncq != using_ncq) 86772109168SMark Lord __mv_stop_dma(ap); 86872109168SMark Lord } 869c5d3e45aSJeff Garzik if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 8700c58912eSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 8710c58912eSMark Lord int hard_port = mv_hardport_from_port(ap->port_no); 8720c58912eSMark Lord void __iomem *hc_mmio = mv_hc_base_from_port( 8730c58912eSMark Lord ap->host->iomap[MV_PRIMARY_BAR], hard_port); 8740c58912eSMark Lord u32 hc_irq_cause, ipending; 8750c58912eSMark Lord 876bdd4dddeSJeff Garzik /* clear EDMA event indicators, if any */ 877f630d562SMark Lord writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 878bdd4dddeSJeff Garzik 8790c58912eSMark Lord /* clear EDMA interrupt indicator, if any */ 8800c58912eSMark Lord hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 8810c58912eSMark Lord ipending = (DEV_IRQ << hard_port) | 8820c58912eSMark Lord (CRPB_DMA_DONE << hard_port); 8830c58912eSMark Lord if (hc_irq_cause & ipending) { 8840c58912eSMark Lord writelfl(hc_irq_cause & ~ipending, 8850c58912eSMark Lord hc_mmio + HC_IRQ_CAUSE_OFS); 8860c58912eSMark Lord } 8870c58912eSMark Lord 88872109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, want_ncq); 8890c58912eSMark Lord 8900c58912eSMark Lord /* clear FIS IRQ Cause */ 8910c58912eSMark Lord writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS); 8920c58912eSMark Lord 893f630d562SMark Lord mv_set_edma_ptrs(port_mmio, hpriv, pp); 894bdd4dddeSJeff Garzik 895f630d562SMark Lord writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS); 896c6fd2807SJeff Garzik pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 897c6fd2807SJeff Garzik } 898f630d562SMark Lord WARN_ON(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); 899c6fd2807SJeff Garzik } 900c6fd2807SJeff Garzik 901c6fd2807SJeff Garzik /** 9020ea9e179SJeff Garzik * __mv_stop_dma - Disable eDMA engine 903c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 904c6fd2807SJeff Garzik * 905c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 906c6fd2807SJeff Garzik * WARN_ON. 907c6fd2807SJeff Garzik * 908c6fd2807SJeff Garzik * LOCKING: 909c6fd2807SJeff Garzik * Inherited from caller. 910c6fd2807SJeff Garzik */ 9110ea9e179SJeff Garzik static int __mv_stop_dma(struct ata_port *ap) 912c6fd2807SJeff Garzik { 913c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 914c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 915c6fd2807SJeff Garzik u32 reg; 916c5d3e45aSJeff Garzik int i, err = 0; 917c6fd2807SJeff Garzik 9184537deb5SJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 919c6fd2807SJeff Garzik /* Disable EDMA if active. The disable bit auto clears. 920c6fd2807SJeff Garzik */ 921c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 922c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 923c6fd2807SJeff Garzik } else { 924c6fd2807SJeff Garzik WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)); 925c6fd2807SJeff Garzik } 926c6fd2807SJeff Garzik 927c6fd2807SJeff Garzik /* now properly wait for the eDMA to stop */ 928c6fd2807SJeff Garzik for (i = 1000; i > 0; i--) { 929c6fd2807SJeff Garzik reg = readl(port_mmio + EDMA_CMD_OFS); 9304537deb5SJeff Garzik if (!(reg & EDMA_EN)) 931c6fd2807SJeff Garzik break; 9324537deb5SJeff Garzik 933c6fd2807SJeff Garzik udelay(100); 934c6fd2807SJeff Garzik } 935c6fd2807SJeff Garzik 936c5d3e45aSJeff Garzik if (reg & EDMA_EN) { 937c6fd2807SJeff Garzik ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 938c5d3e45aSJeff Garzik err = -EIO; 939c6fd2807SJeff Garzik } 940c5d3e45aSJeff Garzik 941c5d3e45aSJeff Garzik return err; 942c6fd2807SJeff Garzik } 943c6fd2807SJeff Garzik 9440ea9e179SJeff Garzik static int mv_stop_dma(struct ata_port *ap) 9450ea9e179SJeff Garzik { 9460ea9e179SJeff Garzik unsigned long flags; 9470ea9e179SJeff Garzik int rc; 9480ea9e179SJeff Garzik 9490ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 9500ea9e179SJeff Garzik rc = __mv_stop_dma(ap); 9510ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 9520ea9e179SJeff Garzik 9530ea9e179SJeff Garzik return rc; 9540ea9e179SJeff Garzik } 9550ea9e179SJeff Garzik 956c6fd2807SJeff Garzik #ifdef ATA_DEBUG 957c6fd2807SJeff Garzik static void mv_dump_mem(void __iomem *start, unsigned bytes) 958c6fd2807SJeff Garzik { 959c6fd2807SJeff Garzik int b, w; 960c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 961c6fd2807SJeff Garzik DPRINTK("%p: ", start + b); 962c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 963c6fd2807SJeff Garzik printk("%08x ", readl(start + b)); 964c6fd2807SJeff Garzik b += sizeof(u32); 965c6fd2807SJeff Garzik } 966c6fd2807SJeff Garzik printk("\n"); 967c6fd2807SJeff Garzik } 968c6fd2807SJeff Garzik } 969c6fd2807SJeff Garzik #endif 970c6fd2807SJeff Garzik 971c6fd2807SJeff Garzik static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes) 972c6fd2807SJeff Garzik { 973c6fd2807SJeff Garzik #ifdef ATA_DEBUG 974c6fd2807SJeff Garzik int b, w; 975c6fd2807SJeff Garzik u32 dw; 976c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 977c6fd2807SJeff Garzik DPRINTK("%02x: ", b); 978c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 979c6fd2807SJeff Garzik (void) pci_read_config_dword(pdev, b, &dw); 980c6fd2807SJeff Garzik printk("%08x ", dw); 981c6fd2807SJeff Garzik b += sizeof(u32); 982c6fd2807SJeff Garzik } 983c6fd2807SJeff Garzik printk("\n"); 984c6fd2807SJeff Garzik } 985c6fd2807SJeff Garzik #endif 986c6fd2807SJeff Garzik } 987c6fd2807SJeff Garzik static void mv_dump_all_regs(void __iomem *mmio_base, int port, 988c6fd2807SJeff Garzik struct pci_dev *pdev) 989c6fd2807SJeff Garzik { 990c6fd2807SJeff Garzik #ifdef ATA_DEBUG 991c6fd2807SJeff Garzik void __iomem *hc_base = mv_hc_base(mmio_base, 992c6fd2807SJeff Garzik port >> MV_PORT_HC_SHIFT); 993c6fd2807SJeff Garzik void __iomem *port_base; 994c6fd2807SJeff Garzik int start_port, num_ports, p, start_hc, num_hcs, hc; 995c6fd2807SJeff Garzik 996c6fd2807SJeff Garzik if (0 > port) { 997c6fd2807SJeff Garzik start_hc = start_port = 0; 998c6fd2807SJeff Garzik num_ports = 8; /* shld be benign for 4 port devs */ 999c6fd2807SJeff Garzik num_hcs = 2; 1000c6fd2807SJeff Garzik } else { 1001c6fd2807SJeff Garzik start_hc = port >> MV_PORT_HC_SHIFT; 1002c6fd2807SJeff Garzik start_port = port; 1003c6fd2807SJeff Garzik num_ports = num_hcs = 1; 1004c6fd2807SJeff Garzik } 1005c6fd2807SJeff Garzik DPRINTK("All registers for port(s) %u-%u:\n", start_port, 1006c6fd2807SJeff Garzik num_ports > 1 ? num_ports - 1 : start_port); 1007c6fd2807SJeff Garzik 1008c6fd2807SJeff Garzik if (NULL != pdev) { 1009c6fd2807SJeff Garzik DPRINTK("PCI config space regs:\n"); 1010c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 1011c6fd2807SJeff Garzik } 1012c6fd2807SJeff Garzik DPRINTK("PCI regs:\n"); 1013c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xc00, 0x3c); 1014c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xd00, 0x34); 1015c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xf00, 0x4); 1016c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0x1d00, 0x6c); 1017c6fd2807SJeff Garzik for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 1018c6fd2807SJeff Garzik hc_base = mv_hc_base(mmio_base, hc); 1019c6fd2807SJeff Garzik DPRINTK("HC regs (HC %i):\n", hc); 1020c6fd2807SJeff Garzik mv_dump_mem(hc_base, 0x1c); 1021c6fd2807SJeff Garzik } 1022c6fd2807SJeff Garzik for (p = start_port; p < start_port + num_ports; p++) { 1023c6fd2807SJeff Garzik port_base = mv_port_base(mmio_base, p); 1024c6fd2807SJeff Garzik DPRINTK("EDMA regs (port %i):\n", p); 1025c6fd2807SJeff Garzik mv_dump_mem(port_base, 0x54); 1026c6fd2807SJeff Garzik DPRINTK("SATA regs (port %i):\n", p); 1027c6fd2807SJeff Garzik mv_dump_mem(port_base+0x300, 0x60); 1028c6fd2807SJeff Garzik } 1029c6fd2807SJeff Garzik #endif 1030c6fd2807SJeff Garzik } 1031c6fd2807SJeff Garzik 1032c6fd2807SJeff Garzik static unsigned int mv_scr_offset(unsigned int sc_reg_in) 1033c6fd2807SJeff Garzik { 1034c6fd2807SJeff Garzik unsigned int ofs; 1035c6fd2807SJeff Garzik 1036c6fd2807SJeff Garzik switch (sc_reg_in) { 1037c6fd2807SJeff Garzik case SCR_STATUS: 1038c6fd2807SJeff Garzik case SCR_CONTROL: 1039c6fd2807SJeff Garzik case SCR_ERROR: 1040c6fd2807SJeff Garzik ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32)); 1041c6fd2807SJeff Garzik break; 1042c6fd2807SJeff Garzik case SCR_ACTIVE: 1043c6fd2807SJeff Garzik ofs = SATA_ACTIVE_OFS; /* active is not with the others */ 1044c6fd2807SJeff Garzik break; 1045c6fd2807SJeff Garzik default: 1046c6fd2807SJeff Garzik ofs = 0xffffffffU; 1047c6fd2807SJeff Garzik break; 1048c6fd2807SJeff Garzik } 1049c6fd2807SJeff Garzik return ofs; 1050c6fd2807SJeff Garzik } 1051c6fd2807SJeff Garzik 1052da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1053c6fd2807SJeff Garzik { 1054c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1055c6fd2807SJeff Garzik 1056da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1057da3dbb17STejun Heo *val = readl(mv_ap_base(ap) + ofs); 1058da3dbb17STejun Heo return 0; 1059da3dbb17STejun Heo } else 1060da3dbb17STejun Heo return -EINVAL; 1061c6fd2807SJeff Garzik } 1062c6fd2807SJeff Garzik 1063da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1064c6fd2807SJeff Garzik { 1065c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1066c6fd2807SJeff Garzik 1067da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1068c6fd2807SJeff Garzik writelfl(val, mv_ap_base(ap) + ofs); 1069da3dbb17STejun Heo return 0; 1070da3dbb17STejun Heo } else 1071da3dbb17STejun Heo return -EINVAL; 1072c6fd2807SJeff Garzik } 1073c6fd2807SJeff Garzik 1074f273827eSMark Lord static void mv6_dev_config(struct ata_device *adev) 1075f273827eSMark Lord { 1076f273827eSMark Lord /* 1077f273827eSMark Lord * We don't have hob_nsect when doing NCQ commands on Gen-II. 1078f273827eSMark Lord * See mv_qc_prep() for more info. 1079f273827eSMark Lord */ 1080f273827eSMark Lord if (adev->flags & ATA_DFLAG_NCQ) 1081f273827eSMark Lord if (adev->max_sectors > ATA_MAX_SECTORS) 1082f273827eSMark Lord adev->max_sectors = ATA_MAX_SECTORS; 1083f273827eSMark Lord } 1084f273827eSMark Lord 108572109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 108672109168SMark Lord void __iomem *port_mmio, int want_ncq) 1087c6fd2807SJeff Garzik { 10880c58912eSMark Lord u32 cfg; 1089c6fd2807SJeff Garzik 1090c6fd2807SJeff Garzik /* set up non-NCQ EDMA configuration */ 10910c58912eSMark Lord cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */ 1092c6fd2807SJeff Garzik 10930c58912eSMark Lord if (IS_GEN_I(hpriv)) 1094c6fd2807SJeff Garzik cfg |= (1 << 8); /* enab config burst size mask */ 1095c6fd2807SJeff Garzik 10960c58912eSMark Lord else if (IS_GEN_II(hpriv)) 1097c6fd2807SJeff Garzik cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 1098c6fd2807SJeff Garzik 1099c6fd2807SJeff Garzik else if (IS_GEN_IIE(hpriv)) { 1100e728eabeSJeff Garzik cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */ 1101e728eabeSJeff Garzik cfg |= (1 << 22); /* enab 4-entry host queue cache */ 1102c6fd2807SJeff Garzik cfg |= (1 << 18); /* enab early completion */ 1103e728eabeSJeff Garzik cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ 1104c6fd2807SJeff Garzik } 1105c6fd2807SJeff Garzik 110672109168SMark Lord if (want_ncq) { 110772109168SMark Lord cfg |= EDMA_CFG_NCQ; 110872109168SMark Lord pp->pp_flags |= MV_PP_FLAG_NCQ_EN; 110972109168SMark Lord } else 111072109168SMark Lord pp->pp_flags &= ~MV_PP_FLAG_NCQ_EN; 111172109168SMark Lord 1112c6fd2807SJeff Garzik writelfl(cfg, port_mmio + EDMA_CFG_OFS); 1113c6fd2807SJeff Garzik } 1114c6fd2807SJeff Garzik 1115da2fa9baSMark Lord static void mv_port_free_dma_mem(struct ata_port *ap) 1116da2fa9baSMark Lord { 1117da2fa9baSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1118da2fa9baSMark Lord struct mv_port_priv *pp = ap->private_data; 1119eb73d558SMark Lord int tag; 1120da2fa9baSMark Lord 1121da2fa9baSMark Lord if (pp->crqb) { 1122da2fa9baSMark Lord dma_pool_free(hpriv->crqb_pool, pp->crqb, pp->crqb_dma); 1123da2fa9baSMark Lord pp->crqb = NULL; 1124da2fa9baSMark Lord } 1125da2fa9baSMark Lord if (pp->crpb) { 1126da2fa9baSMark Lord dma_pool_free(hpriv->crpb_pool, pp->crpb, pp->crpb_dma); 1127da2fa9baSMark Lord pp->crpb = NULL; 1128da2fa9baSMark Lord } 1129eb73d558SMark Lord /* 1130eb73d558SMark Lord * For GEN_I, there's no NCQ, so we have only a single sg_tbl. 1131eb73d558SMark Lord * For later hardware, we have one unique sg_tbl per NCQ tag. 1132eb73d558SMark Lord */ 1133eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1134eb73d558SMark Lord if (pp->sg_tbl[tag]) { 1135eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) 1136eb73d558SMark Lord dma_pool_free(hpriv->sg_tbl_pool, 1137eb73d558SMark Lord pp->sg_tbl[tag], 1138eb73d558SMark Lord pp->sg_tbl_dma[tag]); 1139eb73d558SMark Lord pp->sg_tbl[tag] = NULL; 1140eb73d558SMark Lord } 1141da2fa9baSMark Lord } 1142da2fa9baSMark Lord } 1143da2fa9baSMark Lord 1144c6fd2807SJeff Garzik /** 1145c6fd2807SJeff Garzik * mv_port_start - Port specific init/start routine. 1146c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1147c6fd2807SJeff Garzik * 1148c6fd2807SJeff Garzik * Allocate and point to DMA memory, init port private memory, 1149c6fd2807SJeff Garzik * zero indices. 1150c6fd2807SJeff Garzik * 1151c6fd2807SJeff Garzik * LOCKING: 1152c6fd2807SJeff Garzik * Inherited from caller. 1153c6fd2807SJeff Garzik */ 1154c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap) 1155c6fd2807SJeff Garzik { 1156cca3974eSJeff Garzik struct device *dev = ap->host->dev; 1157cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1158c6fd2807SJeff Garzik struct mv_port_priv *pp; 1159c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 11600ea9e179SJeff Garzik unsigned long flags; 1161*dde20207SJames Bottomley int tag; 1162c6fd2807SJeff Garzik 116324dc5f33STejun Heo pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 1164c6fd2807SJeff Garzik if (!pp) 116524dc5f33STejun Heo return -ENOMEM; 1166da2fa9baSMark Lord ap->private_data = pp; 1167c6fd2807SJeff Garzik 1168da2fa9baSMark Lord pp->crqb = dma_pool_alloc(hpriv->crqb_pool, GFP_KERNEL, &pp->crqb_dma); 1169da2fa9baSMark Lord if (!pp->crqb) 1170da2fa9baSMark Lord return -ENOMEM; 1171da2fa9baSMark Lord memset(pp->crqb, 0, MV_CRQB_Q_SZ); 1172c6fd2807SJeff Garzik 1173da2fa9baSMark Lord pp->crpb = dma_pool_alloc(hpriv->crpb_pool, GFP_KERNEL, &pp->crpb_dma); 1174da2fa9baSMark Lord if (!pp->crpb) 1175da2fa9baSMark Lord goto out_port_free_dma_mem; 1176da2fa9baSMark Lord memset(pp->crpb, 0, MV_CRPB_Q_SZ); 1177c6fd2807SJeff Garzik 1178eb73d558SMark Lord /* 1179eb73d558SMark Lord * For GEN_I, there's no NCQ, so we only allocate a single sg_tbl. 1180eb73d558SMark Lord * For later hardware, we need one unique sg_tbl per NCQ tag. 1181eb73d558SMark Lord */ 1182eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1183eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) { 1184eb73d558SMark Lord pp->sg_tbl[tag] = dma_pool_alloc(hpriv->sg_tbl_pool, 1185eb73d558SMark Lord GFP_KERNEL, &pp->sg_tbl_dma[tag]); 1186eb73d558SMark Lord if (!pp->sg_tbl[tag]) 1187da2fa9baSMark Lord goto out_port_free_dma_mem; 1188eb73d558SMark Lord } else { 1189eb73d558SMark Lord pp->sg_tbl[tag] = pp->sg_tbl[0]; 1190eb73d558SMark Lord pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0]; 1191eb73d558SMark Lord } 1192eb73d558SMark Lord } 1193c6fd2807SJeff Garzik 11940ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 11950ea9e179SJeff Garzik 119672109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, 0); 1197c5d3e45aSJeff Garzik mv_set_edma_ptrs(port_mmio, hpriv, pp); 1198c6fd2807SJeff Garzik 11990ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 12000ea9e179SJeff Garzik 1201c6fd2807SJeff Garzik /* Don't turn on EDMA here...do it before DMA commands only. Else 1202c6fd2807SJeff Garzik * we'll be unable to send non-data, PIO, etc due to restricted access 1203c6fd2807SJeff Garzik * to shadow regs. 1204c6fd2807SJeff Garzik */ 1205c6fd2807SJeff Garzik return 0; 1206da2fa9baSMark Lord 1207da2fa9baSMark Lord out_port_free_dma_mem: 1208da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1209da2fa9baSMark Lord return -ENOMEM; 1210c6fd2807SJeff Garzik } 1211c6fd2807SJeff Garzik 1212c6fd2807SJeff Garzik /** 1213c6fd2807SJeff Garzik * mv_port_stop - Port specific cleanup/stop routine. 1214c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1215c6fd2807SJeff Garzik * 1216c6fd2807SJeff Garzik * Stop DMA, cleanup port memory. 1217c6fd2807SJeff Garzik * 1218c6fd2807SJeff Garzik * LOCKING: 1219cca3974eSJeff Garzik * This routine uses the host lock to protect the DMA stop. 1220c6fd2807SJeff Garzik */ 1221c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap) 1222c6fd2807SJeff Garzik { 1223c6fd2807SJeff Garzik mv_stop_dma(ap); 1224da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1225c6fd2807SJeff Garzik } 1226c6fd2807SJeff Garzik 1227c6fd2807SJeff Garzik /** 1228c6fd2807SJeff Garzik * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries 1229c6fd2807SJeff Garzik * @qc: queued command whose SG list to source from 1230c6fd2807SJeff Garzik * 1231c6fd2807SJeff Garzik * Populate the SG list and mark the last entry. 1232c6fd2807SJeff Garzik * 1233c6fd2807SJeff Garzik * LOCKING: 1234c6fd2807SJeff Garzik * Inherited from caller. 1235c6fd2807SJeff Garzik */ 12366c08772eSJeff Garzik static void mv_fill_sg(struct ata_queued_cmd *qc) 1237c6fd2807SJeff Garzik { 1238c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 1239c6fd2807SJeff Garzik struct scatterlist *sg; 12403be6cbd7SJeff Garzik struct mv_sg *mv_sg, *last_sg = NULL; 1241ff2aeb1eSTejun Heo unsigned int si; 1242c6fd2807SJeff Garzik 1243eb73d558SMark Lord mv_sg = pp->sg_tbl[qc->tag]; 1244ff2aeb1eSTejun Heo for_each_sg(qc->sg, sg, qc->n_elem, si) { 1245d88184fbSJeff Garzik dma_addr_t addr = sg_dma_address(sg); 1246d88184fbSJeff Garzik u32 sg_len = sg_dma_len(sg); 1247c6fd2807SJeff Garzik 12484007b493SOlof Johansson while (sg_len) { 12494007b493SOlof Johansson u32 offset = addr & 0xffff; 12504007b493SOlof Johansson u32 len = sg_len; 12514007b493SOlof Johansson 12524007b493SOlof Johansson if ((offset + sg_len > 0x10000)) 12534007b493SOlof Johansson len = 0x10000 - offset; 12544007b493SOlof Johansson 1255d88184fbSJeff Garzik mv_sg->addr = cpu_to_le32(addr & 0xffffffff); 1256d88184fbSJeff Garzik mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16); 12576c08772eSJeff Garzik mv_sg->flags_size = cpu_to_le32(len & 0xffff); 1258c6fd2807SJeff Garzik 12594007b493SOlof Johansson sg_len -= len; 12604007b493SOlof Johansson addr += len; 12614007b493SOlof Johansson 12623be6cbd7SJeff Garzik last_sg = mv_sg; 1263d88184fbSJeff Garzik mv_sg++; 1264c6fd2807SJeff Garzik } 12654007b493SOlof Johansson } 12663be6cbd7SJeff Garzik 12673be6cbd7SJeff Garzik if (likely(last_sg)) 12683be6cbd7SJeff Garzik last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 1269c6fd2807SJeff Garzik } 1270c6fd2807SJeff Garzik 12715796d1c4SJeff Garzik static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1272c6fd2807SJeff Garzik { 1273c6fd2807SJeff Garzik u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 1274c6fd2807SJeff Garzik (last ? CRQB_CMD_LAST : 0); 1275c6fd2807SJeff Garzik *cmdw = cpu_to_le16(tmp); 1276c6fd2807SJeff Garzik } 1277c6fd2807SJeff Garzik 1278c6fd2807SJeff Garzik /** 1279c6fd2807SJeff Garzik * mv_qc_prep - Host specific command preparation. 1280c6fd2807SJeff Garzik * @qc: queued command to prepare 1281c6fd2807SJeff Garzik * 1282c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1283c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1284c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1285c6fd2807SJeff Garzik * the SG load routine. 1286c6fd2807SJeff Garzik * 1287c6fd2807SJeff Garzik * LOCKING: 1288c6fd2807SJeff Garzik * Inherited from caller. 1289c6fd2807SJeff Garzik */ 1290c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc) 1291c6fd2807SJeff Garzik { 1292c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1293c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1294c6fd2807SJeff Garzik __le16 *cw; 1295c6fd2807SJeff Garzik struct ata_taskfile *tf; 1296c6fd2807SJeff Garzik u16 flags = 0; 1297c6fd2807SJeff Garzik unsigned in_index; 1298c6fd2807SJeff Garzik 1299138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1300138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1301c6fd2807SJeff Garzik return; 1302c6fd2807SJeff Garzik 1303c6fd2807SJeff Garzik /* Fill in command request block 1304c6fd2807SJeff Garzik */ 1305c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1306c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1307c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1308c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 1309c6fd2807SJeff Garzik 1310bdd4dddeSJeff Garzik /* get current queue index from software */ 1311bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1312c6fd2807SJeff Garzik 1313c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr = 1314eb73d558SMark Lord cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1315c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr_hi = 1316eb73d558SMark Lord cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1317c6fd2807SJeff Garzik pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags); 1318c6fd2807SJeff Garzik 1319c6fd2807SJeff Garzik cw = &pp->crqb[in_index].ata_cmd[0]; 1320c6fd2807SJeff Garzik tf = &qc->tf; 1321c6fd2807SJeff Garzik 1322c6fd2807SJeff Garzik /* Sadly, the CRQB cannot accomodate all registers--there are 1323c6fd2807SJeff Garzik * only 11 bytes...so we must pick and choose required 1324c6fd2807SJeff Garzik * registers based on the command. So, we drop feature and 1325c6fd2807SJeff Garzik * hob_feature for [RW] DMA commands, but they are needed for 1326c6fd2807SJeff Garzik * NCQ. NCQ will drop hob_nsect. 1327c6fd2807SJeff Garzik */ 1328c6fd2807SJeff Garzik switch (tf->command) { 1329c6fd2807SJeff Garzik case ATA_CMD_READ: 1330c6fd2807SJeff Garzik case ATA_CMD_READ_EXT: 1331c6fd2807SJeff Garzik case ATA_CMD_WRITE: 1332c6fd2807SJeff Garzik case ATA_CMD_WRITE_EXT: 1333c6fd2807SJeff Garzik case ATA_CMD_WRITE_FUA_EXT: 1334c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0); 1335c6fd2807SJeff Garzik break; 1336c6fd2807SJeff Garzik case ATA_CMD_FPDMA_READ: 1337c6fd2807SJeff Garzik case ATA_CMD_FPDMA_WRITE: 1338c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); 1339c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); 1340c6fd2807SJeff Garzik break; 1341c6fd2807SJeff Garzik default: 1342c6fd2807SJeff Garzik /* The only other commands EDMA supports in non-queued and 1343c6fd2807SJeff Garzik * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none 1344c6fd2807SJeff Garzik * of which are defined/used by Linux. If we get here, this 1345c6fd2807SJeff Garzik * driver needs work. 1346c6fd2807SJeff Garzik * 1347c6fd2807SJeff Garzik * FIXME: modify libata to give qc_prep a return value and 1348c6fd2807SJeff Garzik * return error here. 1349c6fd2807SJeff Garzik */ 1350c6fd2807SJeff Garzik BUG_ON(tf->command); 1351c6fd2807SJeff Garzik break; 1352c6fd2807SJeff Garzik } 1353c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0); 1354c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0); 1355c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0); 1356c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0); 1357c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0); 1358c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0); 1359c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0); 1360c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 1361c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 1362c6fd2807SJeff Garzik 1363c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1364c6fd2807SJeff Garzik return; 1365c6fd2807SJeff Garzik mv_fill_sg(qc); 1366c6fd2807SJeff Garzik } 1367c6fd2807SJeff Garzik 1368c6fd2807SJeff Garzik /** 1369c6fd2807SJeff Garzik * mv_qc_prep_iie - Host specific command preparation. 1370c6fd2807SJeff Garzik * @qc: queued command to prepare 1371c6fd2807SJeff Garzik * 1372c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1373c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1374c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1375c6fd2807SJeff Garzik * the SG load routine. 1376c6fd2807SJeff Garzik * 1377c6fd2807SJeff Garzik * LOCKING: 1378c6fd2807SJeff Garzik * Inherited from caller. 1379c6fd2807SJeff Garzik */ 1380c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc) 1381c6fd2807SJeff Garzik { 1382c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1383c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1384c6fd2807SJeff Garzik struct mv_crqb_iie *crqb; 1385c6fd2807SJeff Garzik struct ata_taskfile *tf; 1386c6fd2807SJeff Garzik unsigned in_index; 1387c6fd2807SJeff Garzik u32 flags = 0; 1388c6fd2807SJeff Garzik 1389138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1390138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1391c6fd2807SJeff Garzik return; 1392c6fd2807SJeff Garzik 1393c6fd2807SJeff Garzik /* Fill in Gen IIE command request block 1394c6fd2807SJeff Garzik */ 1395c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1396c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1397c6fd2807SJeff Garzik 1398c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1399c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 14008c0aeb4aSMark Lord flags |= qc->tag << CRQB_HOSTQ_SHIFT; 1401c6fd2807SJeff Garzik 1402bdd4dddeSJeff Garzik /* get current queue index from software */ 1403bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1404c6fd2807SJeff Garzik 1405c6fd2807SJeff Garzik crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1406eb73d558SMark Lord crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1407eb73d558SMark Lord crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1408c6fd2807SJeff Garzik crqb->flags = cpu_to_le32(flags); 1409c6fd2807SJeff Garzik 1410c6fd2807SJeff Garzik tf = &qc->tf; 1411c6fd2807SJeff Garzik crqb->ata_cmd[0] = cpu_to_le32( 1412c6fd2807SJeff Garzik (tf->command << 16) | 1413c6fd2807SJeff Garzik (tf->feature << 24) 1414c6fd2807SJeff Garzik ); 1415c6fd2807SJeff Garzik crqb->ata_cmd[1] = cpu_to_le32( 1416c6fd2807SJeff Garzik (tf->lbal << 0) | 1417c6fd2807SJeff Garzik (tf->lbam << 8) | 1418c6fd2807SJeff Garzik (tf->lbah << 16) | 1419c6fd2807SJeff Garzik (tf->device << 24) 1420c6fd2807SJeff Garzik ); 1421c6fd2807SJeff Garzik crqb->ata_cmd[2] = cpu_to_le32( 1422c6fd2807SJeff Garzik (tf->hob_lbal << 0) | 1423c6fd2807SJeff Garzik (tf->hob_lbam << 8) | 1424c6fd2807SJeff Garzik (tf->hob_lbah << 16) | 1425c6fd2807SJeff Garzik (tf->hob_feature << 24) 1426c6fd2807SJeff Garzik ); 1427c6fd2807SJeff Garzik crqb->ata_cmd[3] = cpu_to_le32( 1428c6fd2807SJeff Garzik (tf->nsect << 0) | 1429c6fd2807SJeff Garzik (tf->hob_nsect << 8) 1430c6fd2807SJeff Garzik ); 1431c6fd2807SJeff Garzik 1432c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1433c6fd2807SJeff Garzik return; 1434c6fd2807SJeff Garzik mv_fill_sg(qc); 1435c6fd2807SJeff Garzik } 1436c6fd2807SJeff Garzik 1437c6fd2807SJeff Garzik /** 1438c6fd2807SJeff Garzik * mv_qc_issue - Initiate a command to the host 1439c6fd2807SJeff Garzik * @qc: queued command to start 1440c6fd2807SJeff Garzik * 1441c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1442c6fd2807SJeff Garzik * if command is not DMA. Else, it sanity checks our local 1443c6fd2807SJeff Garzik * caches of the request producer/consumer indices then enables 1444c6fd2807SJeff Garzik * DMA and bumps the request producer index. 1445c6fd2807SJeff Garzik * 1446c6fd2807SJeff Garzik * LOCKING: 1447c6fd2807SJeff Garzik * Inherited from caller. 1448c6fd2807SJeff Garzik */ 1449c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 1450c6fd2807SJeff Garzik { 1451c5d3e45aSJeff Garzik struct ata_port *ap = qc->ap; 1452c5d3e45aSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1453c5d3e45aSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1454bdd4dddeSJeff Garzik u32 in_index; 1455c6fd2807SJeff Garzik 1456138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1457138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) { 1458c6fd2807SJeff Garzik /* We're about to send a non-EDMA capable command to the 1459c6fd2807SJeff Garzik * port. Turn off EDMA so there won't be problems accessing 1460c6fd2807SJeff Garzik * shadow block, etc registers. 1461c6fd2807SJeff Garzik */ 14620ea9e179SJeff Garzik __mv_stop_dma(ap); 1463c6fd2807SJeff Garzik return ata_qc_issue_prot(qc); 1464c6fd2807SJeff Garzik } 1465c6fd2807SJeff Garzik 146672109168SMark Lord mv_start_dma(ap, port_mmio, pp, qc->tf.protocol); 1467bdd4dddeSJeff Garzik 1468bdd4dddeSJeff Garzik pp->req_idx++; 1469c6fd2807SJeff Garzik 1470bdd4dddeSJeff Garzik in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 1471c6fd2807SJeff Garzik 1472c6fd2807SJeff Garzik /* and write the request in pointer to kick the EDMA to life */ 1473bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 1474bdd4dddeSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1475c6fd2807SJeff Garzik 1476c6fd2807SJeff Garzik return 0; 1477c6fd2807SJeff Garzik } 1478c6fd2807SJeff Garzik 1479c6fd2807SJeff Garzik /** 1480c6fd2807SJeff Garzik * mv_err_intr - Handle error interrupts on the port 1481c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1482c6fd2807SJeff Garzik * @reset_allowed: bool: 0 == don't trigger from reset here 1483c6fd2807SJeff Garzik * 1484c6fd2807SJeff Garzik * In most cases, just clear the interrupt and move on. However, 1485c6fd2807SJeff Garzik * some cases require an eDMA reset, which is done right before 1486c6fd2807SJeff Garzik * the COMRESET in mv_phy_reset(). The SERR case requires a 1487c6fd2807SJeff Garzik * clear of pending errors in the SATA SERROR register. Finally, 1488c6fd2807SJeff Garzik * if the port disabled DMA, update our cached copy to match. 1489c6fd2807SJeff Garzik * 1490c6fd2807SJeff Garzik * LOCKING: 1491c6fd2807SJeff Garzik * Inherited from caller. 1492c6fd2807SJeff Garzik */ 1493bdd4dddeSJeff Garzik static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 1494c6fd2807SJeff Garzik { 1495c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1496bdd4dddeSJeff Garzik u32 edma_err_cause, eh_freeze_mask, serr = 0; 1497bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1498bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1499bdd4dddeSJeff Garzik unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN); 1500bdd4dddeSJeff Garzik unsigned int action = 0, err_mask = 0; 15019af5c9c9STejun Heo struct ata_eh_info *ehi = &ap->link.eh_info; 1502c6fd2807SJeff Garzik 1503bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1504c6fd2807SJeff Garzik 1505bdd4dddeSJeff Garzik if (!edma_enabled) { 1506bdd4dddeSJeff Garzik /* just a guess: do we need to do this? should we 1507bdd4dddeSJeff Garzik * expand this, and do it in all cases? 1508bdd4dddeSJeff Garzik */ 1509936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1510936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1511c6fd2807SJeff Garzik } 1512bdd4dddeSJeff Garzik 1513bdd4dddeSJeff Garzik edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1514bdd4dddeSJeff Garzik 1515bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause); 1516bdd4dddeSJeff Garzik 1517bdd4dddeSJeff Garzik /* 1518bdd4dddeSJeff Garzik * all generations share these EDMA error cause bits 1519bdd4dddeSJeff Garzik */ 1520bdd4dddeSJeff Garzik 1521bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_DEV) 1522bdd4dddeSJeff Garzik err_mask |= AC_ERR_DEV; 1523bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 15246c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR | 1525bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR)) { 1526bdd4dddeSJeff Garzik err_mask |= AC_ERR_ATA_BUS; 1527bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1528b64bbc39STejun Heo ata_ehi_push_desc(ehi, "parity error"); 1529bdd4dddeSJeff Garzik } 1530bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { 1531bdd4dddeSJeff Garzik ata_ehi_hotplugged(ehi); 1532bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? 1533b64bbc39STejun Heo "dev disconnect" : "dev connect"); 15343606a380SMark Lord action |= ATA_EH_HARDRESET; 1535bdd4dddeSJeff Garzik } 1536bdd4dddeSJeff Garzik 1537ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) { 1538bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE_5; 1539bdd4dddeSJeff Garzik 1540bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 15415ab063e3SHarvey Harrison pp = ap->private_data; 1542c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1543b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1544c6fd2807SJeff Garzik } 1545bdd4dddeSJeff Garzik } else { 1546bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE; 1547bdd4dddeSJeff Garzik 1548bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS) { 15495ab063e3SHarvey Harrison pp = ap->private_data; 1550bdd4dddeSJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1551b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1552bdd4dddeSJeff Garzik } 1553bdd4dddeSJeff Garzik 1554bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SERR) { 1555936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1556936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1557bdd4dddeSJeff Garzik err_mask = AC_ERR_ATA_BUS; 1558bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1559bdd4dddeSJeff Garzik } 1560bdd4dddeSJeff Garzik } 1561c6fd2807SJeff Garzik 1562c6fd2807SJeff Garzik /* Clear EDMA now that SERR cleanup done */ 15633606a380SMark Lord writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1564c6fd2807SJeff Garzik 1565bdd4dddeSJeff Garzik if (!err_mask) { 1566bdd4dddeSJeff Garzik err_mask = AC_ERR_OTHER; 1567bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1568bdd4dddeSJeff Garzik } 1569bdd4dddeSJeff Garzik 1570bdd4dddeSJeff Garzik ehi->serror |= serr; 1571bdd4dddeSJeff Garzik ehi->action |= action; 1572bdd4dddeSJeff Garzik 1573bdd4dddeSJeff Garzik if (qc) 1574bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1575bdd4dddeSJeff Garzik else 1576bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1577bdd4dddeSJeff Garzik 1578bdd4dddeSJeff Garzik if (edma_err_cause & eh_freeze_mask) 1579bdd4dddeSJeff Garzik ata_port_freeze(ap); 1580bdd4dddeSJeff Garzik else 1581bdd4dddeSJeff Garzik ata_port_abort(ap); 1582bdd4dddeSJeff Garzik } 1583bdd4dddeSJeff Garzik 1584bdd4dddeSJeff Garzik static void mv_intr_pio(struct ata_port *ap) 1585bdd4dddeSJeff Garzik { 1586bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1587bdd4dddeSJeff Garzik u8 ata_status; 1588bdd4dddeSJeff Garzik 1589bdd4dddeSJeff Garzik /* ignore spurious intr if drive still BUSY */ 1590bdd4dddeSJeff Garzik ata_status = readb(ap->ioaddr.status_addr); 1591bdd4dddeSJeff Garzik if (unlikely(ata_status & ATA_BUSY)) 1592bdd4dddeSJeff Garzik return; 1593bdd4dddeSJeff Garzik 1594bdd4dddeSJeff Garzik /* get active ATA command */ 15959af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1596bdd4dddeSJeff Garzik if (unlikely(!qc)) /* no active tag */ 1597bdd4dddeSJeff Garzik return; 1598bdd4dddeSJeff Garzik if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */ 1599bdd4dddeSJeff Garzik return; 1600bdd4dddeSJeff Garzik 1601bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1602bdd4dddeSJeff Garzik qc->err_mask |= ac_err_mask(ata_status); 1603bdd4dddeSJeff Garzik ata_qc_complete(qc); 1604bdd4dddeSJeff Garzik } 1605bdd4dddeSJeff Garzik 1606bdd4dddeSJeff Garzik static void mv_intr_edma(struct ata_port *ap) 1607bdd4dddeSJeff Garzik { 1608bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1609bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1610bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1611bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1612bdd4dddeSJeff Garzik u32 out_index, in_index; 1613bdd4dddeSJeff Garzik bool work_done = false; 1614bdd4dddeSJeff Garzik 1615bdd4dddeSJeff Garzik /* get h/w response queue pointer */ 1616bdd4dddeSJeff Garzik in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) 1617bdd4dddeSJeff Garzik >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1618bdd4dddeSJeff Garzik 1619bdd4dddeSJeff Garzik while (1) { 1620bdd4dddeSJeff Garzik u16 status; 16216c1153e0SJeff Garzik unsigned int tag; 1622bdd4dddeSJeff Garzik 1623bdd4dddeSJeff Garzik /* get s/w response queue last-read pointer, and compare */ 1624bdd4dddeSJeff Garzik out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; 1625bdd4dddeSJeff Garzik if (in_index == out_index) 1626bdd4dddeSJeff Garzik break; 1627bdd4dddeSJeff Garzik 1628bdd4dddeSJeff Garzik /* 50xx: get active ATA command */ 1629bdd4dddeSJeff Garzik if (IS_GEN_I(hpriv)) 16309af5c9c9STejun Heo tag = ap->link.active_tag; 1631bdd4dddeSJeff Garzik 16326c1153e0SJeff Garzik /* Gen II/IIE: get active ATA command via tag, to enable 16336c1153e0SJeff Garzik * support for queueing. this works transparently for 16346c1153e0SJeff Garzik * queued and non-queued modes. 1635bdd4dddeSJeff Garzik */ 16368c0aeb4aSMark Lord else 16378c0aeb4aSMark Lord tag = le16_to_cpu(pp->crpb[out_index].id) & 0x1f; 1638bdd4dddeSJeff Garzik 1639bdd4dddeSJeff Garzik qc = ata_qc_from_tag(ap, tag); 1640bdd4dddeSJeff Garzik 1641cb924419SMark Lord /* For non-NCQ mode, the lower 8 bits of status 1642cb924419SMark Lord * are from EDMA_ERR_IRQ_CAUSE_OFS, 1643cb924419SMark Lord * which should be zero if all went well. 1644bdd4dddeSJeff Garzik */ 1645bdd4dddeSJeff Garzik status = le16_to_cpu(pp->crpb[out_index].flags); 1646cb924419SMark Lord if ((status & 0xff) && !(pp->pp_flags & MV_PP_FLAG_NCQ_EN)) { 1647bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1648bdd4dddeSJeff Garzik return; 1649bdd4dddeSJeff Garzik } 1650bdd4dddeSJeff Garzik 1651bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1652bdd4dddeSJeff Garzik if (qc) { 1653bdd4dddeSJeff Garzik qc->err_mask |= 1654bdd4dddeSJeff Garzik ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT); 1655bdd4dddeSJeff Garzik ata_qc_complete(qc); 1656bdd4dddeSJeff Garzik } 1657bdd4dddeSJeff Garzik 1658bdd4dddeSJeff Garzik /* advance software response queue pointer, to 1659bdd4dddeSJeff Garzik * indicate (after the loop completes) to hardware 1660bdd4dddeSJeff Garzik * that we have consumed a response queue entry. 1661bdd4dddeSJeff Garzik */ 1662bdd4dddeSJeff Garzik work_done = true; 1663bdd4dddeSJeff Garzik pp->resp_idx++; 1664bdd4dddeSJeff Garzik } 1665bdd4dddeSJeff Garzik 1666bdd4dddeSJeff Garzik if (work_done) 1667bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 1668bdd4dddeSJeff Garzik (out_index << EDMA_RSP_Q_PTR_SHIFT), 1669bdd4dddeSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1670c6fd2807SJeff Garzik } 1671c6fd2807SJeff Garzik 1672c6fd2807SJeff Garzik /** 1673c6fd2807SJeff Garzik * mv_host_intr - Handle all interrupts on the given host controller 1674cca3974eSJeff Garzik * @host: host specific structure 1675c6fd2807SJeff Garzik * @relevant: port error bits relevant to this host controller 1676c6fd2807SJeff Garzik * @hc: which host controller we're to look at 1677c6fd2807SJeff Garzik * 1678c6fd2807SJeff Garzik * Read then write clear the HC interrupt status then walk each 1679c6fd2807SJeff Garzik * port connected to the HC and see if it needs servicing. Port 1680c6fd2807SJeff Garzik * success ints are reported in the HC interrupt status reg, the 1681c6fd2807SJeff Garzik * port error ints are reported in the higher level main 1682c6fd2807SJeff Garzik * interrupt status register and thus are passed in via the 1683c6fd2807SJeff Garzik * 'relevant' argument. 1684c6fd2807SJeff Garzik * 1685c6fd2807SJeff Garzik * LOCKING: 1686c6fd2807SJeff Garzik * Inherited from caller. 1687c6fd2807SJeff Garzik */ 1688cca3974eSJeff Garzik static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1689c6fd2807SJeff Garzik { 1690f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 1691f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 1692c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1693c6fd2807SJeff Garzik u32 hc_irq_cause; 1694f351b2d6SSaeed Bishara int port, port0, last_port; 1695c6fd2807SJeff Garzik 169635177265SJeff Garzik if (hc == 0) 1697c6fd2807SJeff Garzik port0 = 0; 169835177265SJeff Garzik else 1699c6fd2807SJeff Garzik port0 = MV_PORTS_PER_HC; 1700c6fd2807SJeff Garzik 1701f351b2d6SSaeed Bishara if (HAS_PCI(host)) 1702f351b2d6SSaeed Bishara last_port = port0 + MV_PORTS_PER_HC; 1703f351b2d6SSaeed Bishara else 1704f351b2d6SSaeed Bishara last_port = port0 + hpriv->n_ports; 1705c6fd2807SJeff Garzik /* we'll need the HC success int register in most cases */ 1706c6fd2807SJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1707bdd4dddeSJeff Garzik if (!hc_irq_cause) 1708bdd4dddeSJeff Garzik return; 1709bdd4dddeSJeff Garzik 1710c6fd2807SJeff Garzik writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1711c6fd2807SJeff Garzik 1712c6fd2807SJeff Garzik VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1713c6fd2807SJeff Garzik hc, relevant, hc_irq_cause); 1714c6fd2807SJeff Garzik 17158f71efe2SYinghai Lu for (port = port0; port < last_port; port++) { 1716cca3974eSJeff Garzik struct ata_port *ap = host->ports[port]; 17178f71efe2SYinghai Lu struct mv_port_priv *pp; 1718bdd4dddeSJeff Garzik int have_err_bits, hard_port, shift; 1719c6fd2807SJeff Garzik 1720bdd4dddeSJeff Garzik if ((!ap) || (ap->flags & ATA_FLAG_DISABLED)) 1721c6fd2807SJeff Garzik continue; 1722c6fd2807SJeff Garzik 17238f71efe2SYinghai Lu pp = ap->private_data; 17248f71efe2SYinghai Lu 1725c6fd2807SJeff Garzik shift = port << 1; /* (port * 2) */ 1726c6fd2807SJeff Garzik if (port >= MV_PORTS_PER_HC) { 1727c6fd2807SJeff Garzik shift++; /* skip bit 8 in the HC Main IRQ reg */ 1728c6fd2807SJeff Garzik } 1729bdd4dddeSJeff Garzik have_err_bits = ((PORT0_ERR << shift) & relevant); 1730bdd4dddeSJeff Garzik 1731bdd4dddeSJeff Garzik if (unlikely(have_err_bits)) { 1732bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1733bdd4dddeSJeff Garzik 17349af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1735bdd4dddeSJeff Garzik if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) 1736bdd4dddeSJeff Garzik continue; 1737bdd4dddeSJeff Garzik 1738bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1739bdd4dddeSJeff Garzik continue; 1740c6fd2807SJeff Garzik } 1741c6fd2807SJeff Garzik 1742bdd4dddeSJeff Garzik hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1743bdd4dddeSJeff Garzik 1744bdd4dddeSJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1745bdd4dddeSJeff Garzik if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) 1746bdd4dddeSJeff Garzik mv_intr_edma(ap); 1747bdd4dddeSJeff Garzik } else { 1748bdd4dddeSJeff Garzik if ((DEV_IRQ << hard_port) & hc_irq_cause) 1749bdd4dddeSJeff Garzik mv_intr_pio(ap); 1750c6fd2807SJeff Garzik } 1751c6fd2807SJeff Garzik } 1752c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 1753c6fd2807SJeff Garzik } 1754c6fd2807SJeff Garzik 1755bdd4dddeSJeff Garzik static void mv_pci_error(struct ata_host *host, void __iomem *mmio) 1756bdd4dddeSJeff Garzik { 175702a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 1758bdd4dddeSJeff Garzik struct ata_port *ap; 1759bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1760bdd4dddeSJeff Garzik struct ata_eh_info *ehi; 1761bdd4dddeSJeff Garzik unsigned int i, err_mask, printed = 0; 1762bdd4dddeSJeff Garzik u32 err_cause; 1763bdd4dddeSJeff Garzik 176402a121daSMark Lord err_cause = readl(mmio + hpriv->irq_cause_ofs); 1765bdd4dddeSJeff Garzik 1766bdd4dddeSJeff Garzik dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", 1767bdd4dddeSJeff Garzik err_cause); 1768bdd4dddeSJeff Garzik 1769bdd4dddeSJeff Garzik DPRINTK("All regs @ PCI error\n"); 1770bdd4dddeSJeff Garzik mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 1771bdd4dddeSJeff Garzik 177202a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 1773bdd4dddeSJeff Garzik 1774bdd4dddeSJeff Garzik for (i = 0; i < host->n_ports; i++) { 1775bdd4dddeSJeff Garzik ap = host->ports[i]; 1776936fd732STejun Heo if (!ata_link_offline(&ap->link)) { 17779af5c9c9STejun Heo ehi = &ap->link.eh_info; 1778bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1779bdd4dddeSJeff Garzik if (!printed++) 1780bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, 1781bdd4dddeSJeff Garzik "PCI err cause 0x%08x", err_cause); 1782bdd4dddeSJeff Garzik err_mask = AC_ERR_HOST_BUS; 1783bdd4dddeSJeff Garzik ehi->action = ATA_EH_HARDRESET; 17849af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1785bdd4dddeSJeff Garzik if (qc) 1786bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1787bdd4dddeSJeff Garzik else 1788bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1789bdd4dddeSJeff Garzik 1790bdd4dddeSJeff Garzik ata_port_freeze(ap); 1791bdd4dddeSJeff Garzik } 1792bdd4dddeSJeff Garzik } 1793bdd4dddeSJeff Garzik } 1794bdd4dddeSJeff Garzik 1795c6fd2807SJeff Garzik /** 1796c5d3e45aSJeff Garzik * mv_interrupt - Main interrupt event handler 1797c6fd2807SJeff Garzik * @irq: unused 1798c6fd2807SJeff Garzik * @dev_instance: private data; in this case the host structure 1799c6fd2807SJeff Garzik * 1800c6fd2807SJeff Garzik * Read the read only register to determine if any host 1801c6fd2807SJeff Garzik * controllers have pending interrupts. If so, call lower level 1802c6fd2807SJeff Garzik * routine to handle. Also check for PCI errors which are only 1803c6fd2807SJeff Garzik * reported here. 1804c6fd2807SJeff Garzik * 1805c6fd2807SJeff Garzik * LOCKING: 1806cca3974eSJeff Garzik * This routine holds the host lock while processing pending 1807c6fd2807SJeff Garzik * interrupts. 1808c6fd2807SJeff Garzik */ 18097d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance) 1810c6fd2807SJeff Garzik { 1811cca3974eSJeff Garzik struct ata_host *host = dev_instance; 1812f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 1813c6fd2807SJeff Garzik unsigned int hc, handled = 0, n_hcs; 1814f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 1815646a4da5SMark Lord u32 irq_stat, irq_mask; 1816c6fd2807SJeff Garzik 1817646a4da5SMark Lord spin_lock(&host->lock); 1818f351b2d6SSaeed Bishara 1819f351b2d6SSaeed Bishara irq_stat = readl(hpriv->main_cause_reg_addr); 1820f351b2d6SSaeed Bishara irq_mask = readl(hpriv->main_mask_reg_addr); 1821c6fd2807SJeff Garzik 1822c6fd2807SJeff Garzik /* check the cases where we either have nothing pending or have read 1823c6fd2807SJeff Garzik * a bogus register value which can indicate HW removal or PCI fault 1824c6fd2807SJeff Garzik */ 1825646a4da5SMark Lord if (!(irq_stat & irq_mask) || (0xffffffffU == irq_stat)) 1826646a4da5SMark Lord goto out_unlock; 1827c6fd2807SJeff Garzik 1828cca3974eSJeff Garzik n_hcs = mv_get_hc_count(host->ports[0]->flags); 1829c6fd2807SJeff Garzik 18307bb3c529SSaeed Bishara if (unlikely((irq_stat & PCI_ERR) && HAS_PCI(host))) { 1831bdd4dddeSJeff Garzik mv_pci_error(host, mmio); 1832bdd4dddeSJeff Garzik handled = 1; 1833bdd4dddeSJeff Garzik goto out_unlock; /* skip all other HC irq handling */ 1834bdd4dddeSJeff Garzik } 1835bdd4dddeSJeff Garzik 1836c6fd2807SJeff Garzik for (hc = 0; hc < n_hcs; hc++) { 1837c6fd2807SJeff Garzik u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1838c6fd2807SJeff Garzik if (relevant) { 1839cca3974eSJeff Garzik mv_host_intr(host, relevant, hc); 1840bdd4dddeSJeff Garzik handled = 1; 1841c6fd2807SJeff Garzik } 1842c6fd2807SJeff Garzik } 1843c6fd2807SJeff Garzik 1844bdd4dddeSJeff Garzik out_unlock: 1845cca3974eSJeff Garzik spin_unlock(&host->lock); 1846c6fd2807SJeff Garzik 1847c6fd2807SJeff Garzik return IRQ_RETVAL(handled); 1848c6fd2807SJeff Garzik } 1849c6fd2807SJeff Garzik 1850c6fd2807SJeff Garzik static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) 1851c6fd2807SJeff Garzik { 1852c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); 1853c6fd2807SJeff Garzik unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; 1854c6fd2807SJeff Garzik 1855c6fd2807SJeff Garzik return hc_mmio + ofs; 1856c6fd2807SJeff Garzik } 1857c6fd2807SJeff Garzik 1858c6fd2807SJeff Garzik static unsigned int mv5_scr_offset(unsigned int sc_reg_in) 1859c6fd2807SJeff Garzik { 1860c6fd2807SJeff Garzik unsigned int ofs; 1861c6fd2807SJeff Garzik 1862c6fd2807SJeff Garzik switch (sc_reg_in) { 1863c6fd2807SJeff Garzik case SCR_STATUS: 1864c6fd2807SJeff Garzik case SCR_ERROR: 1865c6fd2807SJeff Garzik case SCR_CONTROL: 1866c6fd2807SJeff Garzik ofs = sc_reg_in * sizeof(u32); 1867c6fd2807SJeff Garzik break; 1868c6fd2807SJeff Garzik default: 1869c6fd2807SJeff Garzik ofs = 0xffffffffU; 1870c6fd2807SJeff Garzik break; 1871c6fd2807SJeff Garzik } 1872c6fd2807SJeff Garzik return ofs; 1873c6fd2807SJeff Garzik } 1874c6fd2807SJeff Garzik 1875da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1876c6fd2807SJeff Garzik { 1877f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 1878f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 18790d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1880c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1881c6fd2807SJeff Garzik 1882da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1883da3dbb17STejun Heo *val = readl(addr + ofs); 1884da3dbb17STejun Heo return 0; 1885da3dbb17STejun Heo } else 1886da3dbb17STejun Heo return -EINVAL; 1887c6fd2807SJeff Garzik } 1888c6fd2807SJeff Garzik 1889da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1890c6fd2807SJeff Garzik { 1891f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 1892f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 18930d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1894c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1895c6fd2807SJeff Garzik 1896da3dbb17STejun Heo if (ofs != 0xffffffffU) { 18970d5ff566STejun Heo writelfl(val, addr + ofs); 1898da3dbb17STejun Heo return 0; 1899da3dbb17STejun Heo } else 1900da3dbb17STejun Heo return -EINVAL; 1901c6fd2807SJeff Garzik } 1902c6fd2807SJeff Garzik 19037bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio) 1904c6fd2807SJeff Garzik { 19057bb3c529SSaeed Bishara struct pci_dev *pdev = to_pci_dev(host->dev); 1906c6fd2807SJeff Garzik int early_5080; 1907c6fd2807SJeff Garzik 190844c10138SAuke Kok early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0); 1909c6fd2807SJeff Garzik 1910c6fd2807SJeff Garzik if (!early_5080) { 1911c6fd2807SJeff Garzik u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1912c6fd2807SJeff Garzik tmp |= (1 << 0); 1913c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1914c6fd2807SJeff Garzik } 1915c6fd2807SJeff Garzik 19167bb3c529SSaeed Bishara mv_reset_pci_bus(host, mmio); 1917c6fd2807SJeff Garzik } 1918c6fd2807SJeff Garzik 1919c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 1920c6fd2807SJeff Garzik { 1921c6fd2807SJeff Garzik writel(0x0fcfffff, mmio + MV_FLASH_CTL); 1922c6fd2807SJeff Garzik } 1923c6fd2807SJeff Garzik 1924c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 1925c6fd2807SJeff Garzik void __iomem *mmio) 1926c6fd2807SJeff Garzik { 1927c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, idx); 1928c6fd2807SJeff Garzik u32 tmp; 1929c6fd2807SJeff Garzik 1930c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1931c6fd2807SJeff Garzik 1932c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ 1933c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ 1934c6fd2807SJeff Garzik } 1935c6fd2807SJeff Garzik 1936c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 1937c6fd2807SJeff Garzik { 1938c6fd2807SJeff Garzik u32 tmp; 1939c6fd2807SJeff Garzik 1940c6fd2807SJeff Garzik writel(0, mmio + MV_GPIO_PORT_CTL); 1941c6fd2807SJeff Garzik 1942c6fd2807SJeff Garzik /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ 1943c6fd2807SJeff Garzik 1944c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1945c6fd2807SJeff Garzik tmp |= ~(1 << 0); 1946c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1947c6fd2807SJeff Garzik } 1948c6fd2807SJeff Garzik 1949c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 1950c6fd2807SJeff Garzik unsigned int port) 1951c6fd2807SJeff Garzik { 1952c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, port); 1953c6fd2807SJeff Garzik const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); 1954c6fd2807SJeff Garzik u32 tmp; 1955c6fd2807SJeff Garzik int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); 1956c6fd2807SJeff Garzik 1957c6fd2807SJeff Garzik if (fix_apm_sq) { 1958c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_LT_MODE); 1959c6fd2807SJeff Garzik tmp |= (1 << 19); 1960c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_LT_MODE); 1961c6fd2807SJeff Garzik 1962c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_CTL); 1963c6fd2807SJeff Garzik tmp &= ~0x3; 1964c6fd2807SJeff Garzik tmp |= 0x1; 1965c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_CTL); 1966c6fd2807SJeff Garzik } 1967c6fd2807SJeff Garzik 1968c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1969c6fd2807SJeff Garzik tmp &= ~mask; 1970c6fd2807SJeff Garzik tmp |= hpriv->signal[port].pre; 1971c6fd2807SJeff Garzik tmp |= hpriv->signal[port].amps; 1972c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_MODE); 1973c6fd2807SJeff Garzik } 1974c6fd2807SJeff Garzik 1975c6fd2807SJeff Garzik 1976c6fd2807SJeff Garzik #undef ZERO 1977c6fd2807SJeff Garzik #define ZERO(reg) writel(0, port_mmio + (reg)) 1978c6fd2807SJeff Garzik static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, 1979c6fd2807SJeff Garzik unsigned int port) 1980c6fd2807SJeff Garzik { 1981c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 1982c6fd2807SJeff Garzik 1983c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 1984c6fd2807SJeff Garzik 1985c6fd2807SJeff Garzik mv_channel_reset(hpriv, mmio, port); 1986c6fd2807SJeff Garzik 1987c6fd2807SJeff Garzik ZERO(0x028); /* command */ 1988c6fd2807SJeff Garzik writel(0x11f, port_mmio + EDMA_CFG_OFS); 1989c6fd2807SJeff Garzik ZERO(0x004); /* timer */ 1990c6fd2807SJeff Garzik ZERO(0x008); /* irq err cause */ 1991c6fd2807SJeff Garzik ZERO(0x00c); /* irq err mask */ 1992c6fd2807SJeff Garzik ZERO(0x010); /* rq bah */ 1993c6fd2807SJeff Garzik ZERO(0x014); /* rq inp */ 1994c6fd2807SJeff Garzik ZERO(0x018); /* rq outp */ 1995c6fd2807SJeff Garzik ZERO(0x01c); /* respq bah */ 1996c6fd2807SJeff Garzik ZERO(0x024); /* respq outp */ 1997c6fd2807SJeff Garzik ZERO(0x020); /* respq inp */ 1998c6fd2807SJeff Garzik ZERO(0x02c); /* test control */ 1999c6fd2807SJeff Garzik writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 2000c6fd2807SJeff Garzik } 2001c6fd2807SJeff Garzik #undef ZERO 2002c6fd2807SJeff Garzik 2003c6fd2807SJeff Garzik #define ZERO(reg) writel(0, hc_mmio + (reg)) 2004c6fd2807SJeff Garzik static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 2005c6fd2807SJeff Garzik unsigned int hc) 2006c6fd2807SJeff Garzik { 2007c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2008c6fd2807SJeff Garzik u32 tmp; 2009c6fd2807SJeff Garzik 2010c6fd2807SJeff Garzik ZERO(0x00c); 2011c6fd2807SJeff Garzik ZERO(0x010); 2012c6fd2807SJeff Garzik ZERO(0x014); 2013c6fd2807SJeff Garzik ZERO(0x018); 2014c6fd2807SJeff Garzik 2015c6fd2807SJeff Garzik tmp = readl(hc_mmio + 0x20); 2016c6fd2807SJeff Garzik tmp &= 0x1c1c1c1c; 2017c6fd2807SJeff Garzik tmp |= 0x03030303; 2018c6fd2807SJeff Garzik writel(tmp, hc_mmio + 0x20); 2019c6fd2807SJeff Garzik } 2020c6fd2807SJeff Garzik #undef ZERO 2021c6fd2807SJeff Garzik 2022c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 2023c6fd2807SJeff Garzik unsigned int n_hc) 2024c6fd2807SJeff Garzik { 2025c6fd2807SJeff Garzik unsigned int hc, port; 2026c6fd2807SJeff Garzik 2027c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 2028c6fd2807SJeff Garzik for (port = 0; port < MV_PORTS_PER_HC; port++) 2029c6fd2807SJeff Garzik mv5_reset_hc_port(hpriv, mmio, 2030c6fd2807SJeff Garzik (hc * MV_PORTS_PER_HC) + port); 2031c6fd2807SJeff Garzik 2032c6fd2807SJeff Garzik mv5_reset_one_hc(hpriv, mmio, hc); 2033c6fd2807SJeff Garzik } 2034c6fd2807SJeff Garzik 2035c6fd2807SJeff Garzik return 0; 2036c6fd2807SJeff Garzik } 2037c6fd2807SJeff Garzik 2038c6fd2807SJeff Garzik #undef ZERO 2039c6fd2807SJeff Garzik #define ZERO(reg) writel(0, mmio + (reg)) 20407bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio) 2041c6fd2807SJeff Garzik { 204202a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 2043c6fd2807SJeff Garzik u32 tmp; 2044c6fd2807SJeff Garzik 2045c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_MODE); 2046c6fd2807SJeff Garzik tmp &= 0xff00ffff; 2047c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_MODE); 2048c6fd2807SJeff Garzik 2049c6fd2807SJeff Garzik ZERO(MV_PCI_DISC_TIMER); 2050c6fd2807SJeff Garzik ZERO(MV_PCI_MSI_TRIGGER); 2051c6fd2807SJeff Garzik writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 2052c6fd2807SJeff Garzik ZERO(HC_MAIN_IRQ_MASK_OFS); 2053c6fd2807SJeff Garzik ZERO(MV_PCI_SERR_MASK); 205402a121daSMark Lord ZERO(hpriv->irq_cause_ofs); 205502a121daSMark Lord ZERO(hpriv->irq_mask_ofs); 2056c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_LOW_ADDRESS); 2057c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_HIGH_ADDRESS); 2058c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_ATTRIBUTE); 2059c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_COMMAND); 2060c6fd2807SJeff Garzik } 2061c6fd2807SJeff Garzik #undef ZERO 2062c6fd2807SJeff Garzik 2063c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 2064c6fd2807SJeff Garzik { 2065c6fd2807SJeff Garzik u32 tmp; 2066c6fd2807SJeff Garzik 2067c6fd2807SJeff Garzik mv5_reset_flash(hpriv, mmio); 2068c6fd2807SJeff Garzik 2069c6fd2807SJeff Garzik tmp = readl(mmio + MV_GPIO_PORT_CTL); 2070c6fd2807SJeff Garzik tmp &= 0x3; 2071c6fd2807SJeff Garzik tmp |= (1 << 5) | (1 << 6); 2072c6fd2807SJeff Garzik writel(tmp, mmio + MV_GPIO_PORT_CTL); 2073c6fd2807SJeff Garzik } 2074c6fd2807SJeff Garzik 2075c6fd2807SJeff Garzik /** 2076c6fd2807SJeff Garzik * mv6_reset_hc - Perform the 6xxx global soft reset 2077c6fd2807SJeff Garzik * @mmio: base address of the HBA 2078c6fd2807SJeff Garzik * 2079c6fd2807SJeff Garzik * This routine only applies to 6xxx parts. 2080c6fd2807SJeff Garzik * 2081c6fd2807SJeff Garzik * LOCKING: 2082c6fd2807SJeff Garzik * Inherited from caller. 2083c6fd2807SJeff Garzik */ 2084c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 2085c6fd2807SJeff Garzik unsigned int n_hc) 2086c6fd2807SJeff Garzik { 2087c6fd2807SJeff Garzik void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS; 2088c6fd2807SJeff Garzik int i, rc = 0; 2089c6fd2807SJeff Garzik u32 t; 2090c6fd2807SJeff Garzik 2091c6fd2807SJeff Garzik /* Following procedure defined in PCI "main command and status 2092c6fd2807SJeff Garzik * register" table. 2093c6fd2807SJeff Garzik */ 2094c6fd2807SJeff Garzik t = readl(reg); 2095c6fd2807SJeff Garzik writel(t | STOP_PCI_MASTER, reg); 2096c6fd2807SJeff Garzik 2097c6fd2807SJeff Garzik for (i = 0; i < 1000; i++) { 2098c6fd2807SJeff Garzik udelay(1); 2099c6fd2807SJeff Garzik t = readl(reg); 21002dcb407eSJeff Garzik if (PCI_MASTER_EMPTY & t) 2101c6fd2807SJeff Garzik break; 2102c6fd2807SJeff Garzik } 2103c6fd2807SJeff Garzik if (!(PCI_MASTER_EMPTY & t)) { 2104c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); 2105c6fd2807SJeff Garzik rc = 1; 2106c6fd2807SJeff Garzik goto done; 2107c6fd2807SJeff Garzik } 2108c6fd2807SJeff Garzik 2109c6fd2807SJeff Garzik /* set reset */ 2110c6fd2807SJeff Garzik i = 5; 2111c6fd2807SJeff Garzik do { 2112c6fd2807SJeff Garzik writel(t | GLOB_SFT_RST, reg); 2113c6fd2807SJeff Garzik t = readl(reg); 2114c6fd2807SJeff Garzik udelay(1); 2115c6fd2807SJeff Garzik } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 2116c6fd2807SJeff Garzik 2117c6fd2807SJeff Garzik if (!(GLOB_SFT_RST & t)) { 2118c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't set global reset\n"); 2119c6fd2807SJeff Garzik rc = 1; 2120c6fd2807SJeff Garzik goto done; 2121c6fd2807SJeff Garzik } 2122c6fd2807SJeff Garzik 2123c6fd2807SJeff Garzik /* clear reset and *reenable the PCI master* (not mentioned in spec) */ 2124c6fd2807SJeff Garzik i = 5; 2125c6fd2807SJeff Garzik do { 2126c6fd2807SJeff Garzik writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); 2127c6fd2807SJeff Garzik t = readl(reg); 2128c6fd2807SJeff Garzik udelay(1); 2129c6fd2807SJeff Garzik } while ((GLOB_SFT_RST & t) && (i-- > 0)); 2130c6fd2807SJeff Garzik 2131c6fd2807SJeff Garzik if (GLOB_SFT_RST & t) { 2132c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 2133c6fd2807SJeff Garzik rc = 1; 2134c6fd2807SJeff Garzik } 2135c6fd2807SJeff Garzik done: 2136c6fd2807SJeff Garzik return rc; 2137c6fd2807SJeff Garzik } 2138c6fd2807SJeff Garzik 2139c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 2140c6fd2807SJeff Garzik void __iomem *mmio) 2141c6fd2807SJeff Garzik { 2142c6fd2807SJeff Garzik void __iomem *port_mmio; 2143c6fd2807SJeff Garzik u32 tmp; 2144c6fd2807SJeff Garzik 2145c6fd2807SJeff Garzik tmp = readl(mmio + MV_RESET_CFG); 2146c6fd2807SJeff Garzik if ((tmp & (1 << 0)) == 0) { 2147c6fd2807SJeff Garzik hpriv->signal[idx].amps = 0x7 << 8; 2148c6fd2807SJeff Garzik hpriv->signal[idx].pre = 0x1 << 5; 2149c6fd2807SJeff Garzik return; 2150c6fd2807SJeff Garzik } 2151c6fd2807SJeff Garzik 2152c6fd2807SJeff Garzik port_mmio = mv_port_base(mmio, idx); 2153c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE2); 2154c6fd2807SJeff Garzik 2155c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 2156c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 2157c6fd2807SJeff Garzik } 2158c6fd2807SJeff Garzik 2159c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 2160c6fd2807SJeff Garzik { 2161c6fd2807SJeff Garzik writel(0x00000060, mmio + MV_GPIO_PORT_CTL); 2162c6fd2807SJeff Garzik } 2163c6fd2807SJeff Garzik 2164c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 2165c6fd2807SJeff Garzik unsigned int port) 2166c6fd2807SJeff Garzik { 2167c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2168c6fd2807SJeff Garzik 2169c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2170c6fd2807SJeff Garzik int fix_phy_mode2 = 2171c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2172c6fd2807SJeff Garzik int fix_phy_mode4 = 2173c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2174c6fd2807SJeff Garzik u32 m2, tmp; 2175c6fd2807SJeff Garzik 2176c6fd2807SJeff Garzik if (fix_phy_mode2) { 2177c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2178c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2179c6fd2807SJeff Garzik m2 |= (1 << 31); 2180c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2181c6fd2807SJeff Garzik 2182c6fd2807SJeff Garzik udelay(200); 2183c6fd2807SJeff Garzik 2184c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2185c6fd2807SJeff Garzik m2 &= ~((1 << 16) | (1 << 31)); 2186c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2187c6fd2807SJeff Garzik 2188c6fd2807SJeff Garzik udelay(200); 2189c6fd2807SJeff Garzik } 2190c6fd2807SJeff Garzik 2191c6fd2807SJeff Garzik /* who knows what this magic does */ 2192c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE3); 2193c6fd2807SJeff Garzik tmp &= ~0x7F800000; 2194c6fd2807SJeff Garzik tmp |= 0x2A800000; 2195c6fd2807SJeff Garzik writel(tmp, port_mmio + PHY_MODE3); 2196c6fd2807SJeff Garzik 2197c6fd2807SJeff Garzik if (fix_phy_mode4) { 2198c6fd2807SJeff Garzik u32 m4; 2199c6fd2807SJeff Garzik 2200c6fd2807SJeff Garzik m4 = readl(port_mmio + PHY_MODE4); 2201c6fd2807SJeff Garzik 2202c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2203c6fd2807SJeff Garzik tmp = readl(port_mmio + 0x310); 2204c6fd2807SJeff Garzik 2205c6fd2807SJeff Garzik m4 = (m4 & ~(1 << 1)) | (1 << 0); 2206c6fd2807SJeff Garzik 2207c6fd2807SJeff Garzik writel(m4, port_mmio + PHY_MODE4); 2208c6fd2807SJeff Garzik 2209c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2210c6fd2807SJeff Garzik writel(tmp, port_mmio + 0x310); 2211c6fd2807SJeff Garzik } 2212c6fd2807SJeff Garzik 2213c6fd2807SJeff Garzik /* Revert values of pre-emphasis and signal amps to the saved ones */ 2214c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2215c6fd2807SJeff Garzik 2216c6fd2807SJeff Garzik m2 &= ~MV_M2_PREAMP_MASK; 2217c6fd2807SJeff Garzik m2 |= hpriv->signal[port].amps; 2218c6fd2807SJeff Garzik m2 |= hpriv->signal[port].pre; 2219c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2220c6fd2807SJeff Garzik 2221c6fd2807SJeff Garzik /* according to mvSata 3.6.1, some IIE values are fixed */ 2222c6fd2807SJeff Garzik if (IS_GEN_IIE(hpriv)) { 2223c6fd2807SJeff Garzik m2 &= ~0xC30FF01F; 2224c6fd2807SJeff Garzik m2 |= 0x0000900F; 2225c6fd2807SJeff Garzik } 2226c6fd2807SJeff Garzik 2227c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2228c6fd2807SJeff Garzik } 2229c6fd2807SJeff Garzik 2230f351b2d6SSaeed Bishara /* TODO: use the generic LED interface to configure the SATA Presence */ 2231f351b2d6SSaeed Bishara /* & Acitivy LEDs on the board */ 2232f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 2233f351b2d6SSaeed Bishara void __iomem *mmio) 2234f351b2d6SSaeed Bishara { 2235f351b2d6SSaeed Bishara return; 2236f351b2d6SSaeed Bishara } 2237f351b2d6SSaeed Bishara 2238f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 2239f351b2d6SSaeed Bishara void __iomem *mmio) 2240f351b2d6SSaeed Bishara { 2241f351b2d6SSaeed Bishara void __iomem *port_mmio; 2242f351b2d6SSaeed Bishara u32 tmp; 2243f351b2d6SSaeed Bishara 2244f351b2d6SSaeed Bishara port_mmio = mv_port_base(mmio, idx); 2245f351b2d6SSaeed Bishara tmp = readl(port_mmio + PHY_MODE2); 2246f351b2d6SSaeed Bishara 2247f351b2d6SSaeed Bishara hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 2248f351b2d6SSaeed Bishara hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 2249f351b2d6SSaeed Bishara } 2250f351b2d6SSaeed Bishara 2251f351b2d6SSaeed Bishara #undef ZERO 2252f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, port_mmio + (reg)) 2253f351b2d6SSaeed Bishara static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv, 2254f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int port) 2255f351b2d6SSaeed Bishara { 2256f351b2d6SSaeed Bishara void __iomem *port_mmio = mv_port_base(mmio, port); 2257f351b2d6SSaeed Bishara 2258f351b2d6SSaeed Bishara writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 2259f351b2d6SSaeed Bishara 2260f351b2d6SSaeed Bishara mv_channel_reset(hpriv, mmio, port); 2261f351b2d6SSaeed Bishara 2262f351b2d6SSaeed Bishara ZERO(0x028); /* command */ 2263f351b2d6SSaeed Bishara writel(0x101f, port_mmio + EDMA_CFG_OFS); 2264f351b2d6SSaeed Bishara ZERO(0x004); /* timer */ 2265f351b2d6SSaeed Bishara ZERO(0x008); /* irq err cause */ 2266f351b2d6SSaeed Bishara ZERO(0x00c); /* irq err mask */ 2267f351b2d6SSaeed Bishara ZERO(0x010); /* rq bah */ 2268f351b2d6SSaeed Bishara ZERO(0x014); /* rq inp */ 2269f351b2d6SSaeed Bishara ZERO(0x018); /* rq outp */ 2270f351b2d6SSaeed Bishara ZERO(0x01c); /* respq bah */ 2271f351b2d6SSaeed Bishara ZERO(0x024); /* respq outp */ 2272f351b2d6SSaeed Bishara ZERO(0x020); /* respq inp */ 2273f351b2d6SSaeed Bishara ZERO(0x02c); /* test control */ 2274f351b2d6SSaeed Bishara writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 2275f351b2d6SSaeed Bishara } 2276f351b2d6SSaeed Bishara 2277f351b2d6SSaeed Bishara #undef ZERO 2278f351b2d6SSaeed Bishara 2279f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, hc_mmio + (reg)) 2280f351b2d6SSaeed Bishara static void mv_soc_reset_one_hc(struct mv_host_priv *hpriv, 2281f351b2d6SSaeed Bishara void __iomem *mmio) 2282f351b2d6SSaeed Bishara { 2283f351b2d6SSaeed Bishara void __iomem *hc_mmio = mv_hc_base(mmio, 0); 2284f351b2d6SSaeed Bishara 2285f351b2d6SSaeed Bishara ZERO(0x00c); 2286f351b2d6SSaeed Bishara ZERO(0x010); 2287f351b2d6SSaeed Bishara ZERO(0x014); 2288f351b2d6SSaeed Bishara 2289f351b2d6SSaeed Bishara } 2290f351b2d6SSaeed Bishara 2291f351b2d6SSaeed Bishara #undef ZERO 2292f351b2d6SSaeed Bishara 2293f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 2294f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc) 2295f351b2d6SSaeed Bishara { 2296f351b2d6SSaeed Bishara unsigned int port; 2297f351b2d6SSaeed Bishara 2298f351b2d6SSaeed Bishara for (port = 0; port < hpriv->n_ports; port++) 2299f351b2d6SSaeed Bishara mv_soc_reset_hc_port(hpriv, mmio, port); 2300f351b2d6SSaeed Bishara 2301f351b2d6SSaeed Bishara mv_soc_reset_one_hc(hpriv, mmio); 2302f351b2d6SSaeed Bishara 2303f351b2d6SSaeed Bishara return 0; 2304f351b2d6SSaeed Bishara } 2305f351b2d6SSaeed Bishara 2306f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 2307f351b2d6SSaeed Bishara void __iomem *mmio) 2308f351b2d6SSaeed Bishara { 2309f351b2d6SSaeed Bishara return; 2310f351b2d6SSaeed Bishara } 2311f351b2d6SSaeed Bishara 2312f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio) 2313f351b2d6SSaeed Bishara { 2314f351b2d6SSaeed Bishara return; 2315f351b2d6SSaeed Bishara } 2316f351b2d6SSaeed Bishara 2317c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 2318c6fd2807SJeff Garzik unsigned int port_no) 2319c6fd2807SJeff Garzik { 2320c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port_no); 2321c6fd2807SJeff Garzik 2322c6fd2807SJeff Garzik writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); 2323c6fd2807SJeff Garzik 2324ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2325c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2326c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2327c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2328c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2329c6fd2807SJeff Garzik } 2330c6fd2807SJeff Garzik 2331c6fd2807SJeff Garzik udelay(25); /* allow reset propagation */ 2332c6fd2807SJeff Garzik 2333c6fd2807SJeff Garzik /* Spec never mentions clearing the bit. Marvell's driver does 2334c6fd2807SJeff Garzik * clear the bit, however. 2335c6fd2807SJeff Garzik */ 2336c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_CMD_OFS); 2337c6fd2807SJeff Garzik 2338c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port_no); 2339c6fd2807SJeff Garzik 2340ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2341c6fd2807SJeff Garzik mdelay(1); 2342c6fd2807SJeff Garzik } 2343c6fd2807SJeff Garzik 2344c6fd2807SJeff Garzik /** 2345bdd4dddeSJeff Garzik * mv_phy_reset - Perform eDMA reset followed by COMRESET 2346c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 2347c6fd2807SJeff Garzik * 2348c6fd2807SJeff Garzik * Part of this is taken from __sata_phy_reset and modified to 2349c6fd2807SJeff Garzik * not sleep since this routine gets called from interrupt level. 2350c6fd2807SJeff Garzik * 2351c6fd2807SJeff Garzik * LOCKING: 2352c6fd2807SJeff Garzik * Inherited from caller. This is coded to safe to call at 2353c6fd2807SJeff Garzik * interrupt level, i.e. it does not sleep. 2354c6fd2807SJeff Garzik */ 2355bdd4dddeSJeff Garzik static void mv_phy_reset(struct ata_port *ap, unsigned int *class, 2356bdd4dddeSJeff Garzik unsigned long deadline) 2357c6fd2807SJeff Garzik { 2358c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 2359cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2360c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2361c6fd2807SJeff Garzik int retry = 5; 2362c6fd2807SJeff Garzik u32 sstatus; 2363c6fd2807SJeff Garzik 2364c6fd2807SJeff Garzik VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 2365c6fd2807SJeff Garzik 2366da3dbb17STejun Heo #ifdef DEBUG 2367da3dbb17STejun Heo { 2368da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2369da3dbb17STejun Heo 2370da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2371da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2372da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2373c6fd2807SJeff Garzik DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 23742d79ab8fSSaeed Bishara "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2375da3dbb17STejun Heo } 2376da3dbb17STejun Heo #endif 2377c6fd2807SJeff Garzik 2378c6fd2807SJeff Garzik /* Issue COMRESET via SControl */ 2379c6fd2807SJeff Garzik comreset_retry: 2380936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x301); 2381bdd4dddeSJeff Garzik msleep(1); 2382c6fd2807SJeff Garzik 2383936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x300); 2384bdd4dddeSJeff Garzik msleep(20); 2385c6fd2807SJeff Garzik 2386c6fd2807SJeff Garzik do { 2387936fd732STejun Heo sata_scr_read(&ap->link, SCR_STATUS, &sstatus); 2388dd1dc802SJeff Garzik if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 2389c6fd2807SJeff Garzik break; 2390c6fd2807SJeff Garzik 2391bdd4dddeSJeff Garzik msleep(1); 2392c5d3e45aSJeff Garzik } while (time_before(jiffies, deadline)); 2393c6fd2807SJeff Garzik 2394c6fd2807SJeff Garzik /* work around errata */ 2395ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv) && 2396c6fd2807SJeff Garzik (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && 2397c6fd2807SJeff Garzik (retry-- > 0)) 2398c6fd2807SJeff Garzik goto comreset_retry; 2399c6fd2807SJeff Garzik 2400da3dbb17STejun Heo #ifdef DEBUG 2401da3dbb17STejun Heo { 2402da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2403da3dbb17STejun Heo 2404da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2405da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2406da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2407c6fd2807SJeff Garzik DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " 2408da3dbb17STejun Heo "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2409da3dbb17STejun Heo } 2410da3dbb17STejun Heo #endif 2411c6fd2807SJeff Garzik 2412936fd732STejun Heo if (ata_link_offline(&ap->link)) { 2413bdd4dddeSJeff Garzik *class = ATA_DEV_NONE; 2414c6fd2807SJeff Garzik return; 2415c6fd2807SJeff Garzik } 2416c6fd2807SJeff Garzik 2417c6fd2807SJeff Garzik /* even after SStatus reflects that device is ready, 2418c6fd2807SJeff Garzik * it seems to take a while for link to be fully 2419c6fd2807SJeff Garzik * established (and thus Status no longer 0x80/0x7F), 2420c6fd2807SJeff Garzik * so we poll a bit for that, here. 2421c6fd2807SJeff Garzik */ 2422c6fd2807SJeff Garzik retry = 20; 2423c6fd2807SJeff Garzik while (1) { 2424c6fd2807SJeff Garzik u8 drv_stat = ata_check_status(ap); 2425c6fd2807SJeff Garzik if ((drv_stat != 0x80) && (drv_stat != 0x7f)) 2426c6fd2807SJeff Garzik break; 2427bdd4dddeSJeff Garzik msleep(500); 2428c6fd2807SJeff Garzik if (retry-- <= 0) 2429c6fd2807SJeff Garzik break; 2430bdd4dddeSJeff Garzik if (time_after(jiffies, deadline)) 2431bdd4dddeSJeff Garzik break; 2432c6fd2807SJeff Garzik } 2433c6fd2807SJeff Garzik 2434bdd4dddeSJeff Garzik /* FIXME: if we passed the deadline, the following 2435bdd4dddeSJeff Garzik * code probably produces an invalid result 2436bdd4dddeSJeff Garzik */ 2437c6fd2807SJeff Garzik 2438bdd4dddeSJeff Garzik /* finally, read device signature from TF registers */ 24393f19859eSTejun Heo *class = ata_dev_try_classify(ap->link.device, 1, NULL); 2440c6fd2807SJeff Garzik 2441c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2442c6fd2807SJeff Garzik 2443bdd4dddeSJeff Garzik WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN); 2444c6fd2807SJeff Garzik 2445c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 2446c6fd2807SJeff Garzik } 2447c6fd2807SJeff Garzik 2448cc0680a5STejun Heo static int mv_prereset(struct ata_link *link, unsigned long deadline) 2449c6fd2807SJeff Garzik { 2450cc0680a5STejun Heo struct ata_port *ap = link->ap; 2451bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 2452cc0680a5STejun Heo struct ata_eh_context *ehc = &link->eh_context; 2453bdd4dddeSJeff Garzik int rc; 2454bdd4dddeSJeff Garzik 2455bdd4dddeSJeff Garzik rc = mv_stop_dma(ap); 2456bdd4dddeSJeff Garzik if (rc) 2457bdd4dddeSJeff Garzik ehc->i.action |= ATA_EH_HARDRESET; 2458bdd4dddeSJeff Garzik 2459bdd4dddeSJeff Garzik if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) { 2460bdd4dddeSJeff Garzik pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET; 2461bdd4dddeSJeff Garzik ehc->i.action |= ATA_EH_HARDRESET; 2462c6fd2807SJeff Garzik } 2463c6fd2807SJeff Garzik 2464bdd4dddeSJeff Garzik /* if we're about to do hardreset, nothing more to do */ 2465bdd4dddeSJeff Garzik if (ehc->i.action & ATA_EH_HARDRESET) 2466bdd4dddeSJeff Garzik return 0; 2467bdd4dddeSJeff Garzik 2468cc0680a5STejun Heo if (ata_link_online(link)) 2469bdd4dddeSJeff Garzik rc = ata_wait_ready(ap, deadline); 2470bdd4dddeSJeff Garzik else 2471bdd4dddeSJeff Garzik rc = -ENODEV; 2472bdd4dddeSJeff Garzik 2473bdd4dddeSJeff Garzik return rc; 2474bdd4dddeSJeff Garzik } 2475bdd4dddeSJeff Garzik 2476cc0680a5STejun Heo static int mv_hardreset(struct ata_link *link, unsigned int *class, 2477bdd4dddeSJeff Garzik unsigned long deadline) 2478bdd4dddeSJeff Garzik { 2479cc0680a5STejun Heo struct ata_port *ap = link->ap; 2480bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2481f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2482bdd4dddeSJeff Garzik 2483bdd4dddeSJeff Garzik mv_stop_dma(ap); 2484bdd4dddeSJeff Garzik 2485bdd4dddeSJeff Garzik mv_channel_reset(hpriv, mmio, ap->port_no); 2486bdd4dddeSJeff Garzik 2487bdd4dddeSJeff Garzik mv_phy_reset(ap, class, deadline); 2488bdd4dddeSJeff Garzik 2489bdd4dddeSJeff Garzik return 0; 2490bdd4dddeSJeff Garzik } 2491bdd4dddeSJeff Garzik 2492cc0680a5STejun Heo static void mv_postreset(struct ata_link *link, unsigned int *classes) 2493bdd4dddeSJeff Garzik { 2494cc0680a5STejun Heo struct ata_port *ap = link->ap; 2495bdd4dddeSJeff Garzik u32 serr; 2496bdd4dddeSJeff Garzik 2497bdd4dddeSJeff Garzik /* print link status */ 2498cc0680a5STejun Heo sata_print_link_status(link); 2499bdd4dddeSJeff Garzik 2500bdd4dddeSJeff Garzik /* clear SError */ 2501cc0680a5STejun Heo sata_scr_read(link, SCR_ERROR, &serr); 2502cc0680a5STejun Heo sata_scr_write_flush(link, SCR_ERROR, serr); 2503bdd4dddeSJeff Garzik 2504bdd4dddeSJeff Garzik /* bail out if no device is present */ 2505bdd4dddeSJeff Garzik if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { 2506bdd4dddeSJeff Garzik DPRINTK("EXIT, no device\n"); 2507bdd4dddeSJeff Garzik return; 2508bdd4dddeSJeff Garzik } 2509bdd4dddeSJeff Garzik 2510bdd4dddeSJeff Garzik /* set up device control */ 2511bdd4dddeSJeff Garzik iowrite8(ap->ctl, ap->ioaddr.ctl_addr); 2512bdd4dddeSJeff Garzik } 2513bdd4dddeSJeff Garzik 2514bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap) 2515bdd4dddeSJeff Garzik { 2516bdd4dddeSJeff Garzik ata_do_eh(ap, mv_prereset, ata_std_softreset, 2517bdd4dddeSJeff Garzik mv_hardreset, mv_postreset); 2518bdd4dddeSJeff Garzik } 2519bdd4dddeSJeff Garzik 2520bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap) 2521c6fd2807SJeff Garzik { 2522f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 2523bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2524bdd4dddeSJeff Garzik u32 tmp, mask; 2525bdd4dddeSJeff Garzik unsigned int shift; 2526c6fd2807SJeff Garzik 2527bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2528c6fd2807SJeff Garzik 2529bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2530bdd4dddeSJeff Garzik if (hc > 0) 2531bdd4dddeSJeff Garzik shift++; 2532c6fd2807SJeff Garzik 2533bdd4dddeSJeff Garzik mask = 0x3 << shift; 2534c6fd2807SJeff Garzik 2535bdd4dddeSJeff Garzik /* disable assertion of portN err, done events */ 2536f351b2d6SSaeed Bishara tmp = readl(hpriv->main_mask_reg_addr); 2537f351b2d6SSaeed Bishara writelfl(tmp & ~mask, hpriv->main_mask_reg_addr); 2538c6fd2807SJeff Garzik } 2539bdd4dddeSJeff Garzik 2540bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap) 2541bdd4dddeSJeff Garzik { 2542f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 2543f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2544bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2545bdd4dddeSJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2546bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2547bdd4dddeSJeff Garzik u32 tmp, mask, hc_irq_cause; 2548bdd4dddeSJeff Garzik unsigned int shift, hc_port_no = ap->port_no; 2549bdd4dddeSJeff Garzik 2550bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2551bdd4dddeSJeff Garzik 2552bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2553bdd4dddeSJeff Garzik if (hc > 0) { 2554bdd4dddeSJeff Garzik shift++; 2555bdd4dddeSJeff Garzik hc_port_no -= 4; 2556bdd4dddeSJeff Garzik } 2557bdd4dddeSJeff Garzik 2558bdd4dddeSJeff Garzik mask = 0x3 << shift; 2559bdd4dddeSJeff Garzik 2560bdd4dddeSJeff Garzik /* clear EDMA errors on this port */ 2561bdd4dddeSJeff Garzik writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2562bdd4dddeSJeff Garzik 2563bdd4dddeSJeff Garzik /* clear pending irq events */ 2564bdd4dddeSJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 2565bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */ 2566bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */ 2567bdd4dddeSJeff Garzik writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 2568bdd4dddeSJeff Garzik 2569bdd4dddeSJeff Garzik /* enable assertion of portN err, done events */ 2570f351b2d6SSaeed Bishara tmp = readl(hpriv->main_mask_reg_addr); 2571f351b2d6SSaeed Bishara writelfl(tmp | mask, hpriv->main_mask_reg_addr); 2572c6fd2807SJeff Garzik } 2573c6fd2807SJeff Garzik 2574c6fd2807SJeff Garzik /** 2575c6fd2807SJeff Garzik * mv_port_init - Perform some early initialization on a single port. 2576c6fd2807SJeff Garzik * @port: libata data structure storing shadow register addresses 2577c6fd2807SJeff Garzik * @port_mmio: base address of the port 2578c6fd2807SJeff Garzik * 2579c6fd2807SJeff Garzik * Initialize shadow register mmio addresses, clear outstanding 2580c6fd2807SJeff Garzik * interrupts on the port, and unmask interrupts for the future 2581c6fd2807SJeff Garzik * start of the port. 2582c6fd2807SJeff Garzik * 2583c6fd2807SJeff Garzik * LOCKING: 2584c6fd2807SJeff Garzik * Inherited from caller. 2585c6fd2807SJeff Garzik */ 2586c6fd2807SJeff Garzik static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 2587c6fd2807SJeff Garzik { 25880d5ff566STejun Heo void __iomem *shd_base = port_mmio + SHD_BLK_OFS; 2589c6fd2807SJeff Garzik unsigned serr_ofs; 2590c6fd2807SJeff Garzik 2591c6fd2807SJeff Garzik /* PIO related setup 2592c6fd2807SJeff Garzik */ 2593c6fd2807SJeff Garzik port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); 2594c6fd2807SJeff Garzik port->error_addr = 2595c6fd2807SJeff Garzik port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); 2596c6fd2807SJeff Garzik port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); 2597c6fd2807SJeff Garzik port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); 2598c6fd2807SJeff Garzik port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); 2599c6fd2807SJeff Garzik port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); 2600c6fd2807SJeff Garzik port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); 2601c6fd2807SJeff Garzik port->status_addr = 2602c6fd2807SJeff Garzik port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); 2603c6fd2807SJeff Garzik /* special case: control/altstatus doesn't have ATA_REG_ address */ 2604c6fd2807SJeff Garzik port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; 2605c6fd2807SJeff Garzik 2606c6fd2807SJeff Garzik /* unused: */ 26078d9db2d2SRandy Dunlap port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL; 2608c6fd2807SJeff Garzik 2609c6fd2807SJeff Garzik /* Clear any currently outstanding port interrupt conditions */ 2610c6fd2807SJeff Garzik serr_ofs = mv_scr_offset(SCR_ERROR); 2611c6fd2807SJeff Garzik writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs); 2612c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2613c6fd2807SJeff Garzik 2614646a4da5SMark Lord /* unmask all non-transient EDMA error interrupts */ 2615646a4da5SMark Lord writelfl(~EDMA_ERR_IRQ_TRANSIENT, port_mmio + EDMA_ERR_IRQ_MASK_OFS); 2616c6fd2807SJeff Garzik 2617c6fd2807SJeff Garzik VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 2618c6fd2807SJeff Garzik readl(port_mmio + EDMA_CFG_OFS), 2619c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), 2620c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); 2621c6fd2807SJeff Garzik } 2622c6fd2807SJeff Garzik 26234447d351STejun Heo static int mv_chip_id(struct ata_host *host, unsigned int board_idx) 2624c6fd2807SJeff Garzik { 26254447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 26264447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2627c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2628c6fd2807SJeff Garzik 2629c6fd2807SJeff Garzik switch (board_idx) { 2630c6fd2807SJeff Garzik case chip_5080: 2631c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2632ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2633c6fd2807SJeff Garzik 263444c10138SAuke Kok switch (pdev->revision) { 2635c6fd2807SJeff Garzik case 0x1: 2636c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2637c6fd2807SJeff Garzik break; 2638c6fd2807SJeff Garzik case 0x3: 2639c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2640c6fd2807SJeff Garzik break; 2641c6fd2807SJeff Garzik default: 2642c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2643c6fd2807SJeff Garzik "Applying 50XXB2 workarounds to unknown rev\n"); 2644c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2645c6fd2807SJeff Garzik break; 2646c6fd2807SJeff Garzik } 2647c6fd2807SJeff Garzik break; 2648c6fd2807SJeff Garzik 2649c6fd2807SJeff Garzik case chip_504x: 2650c6fd2807SJeff Garzik case chip_508x: 2651c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2652ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2653c6fd2807SJeff Garzik 265444c10138SAuke Kok switch (pdev->revision) { 2655c6fd2807SJeff Garzik case 0x0: 2656c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2657c6fd2807SJeff Garzik break; 2658c6fd2807SJeff Garzik case 0x3: 2659c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2660c6fd2807SJeff Garzik break; 2661c6fd2807SJeff Garzik default: 2662c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2663c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2664c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2665c6fd2807SJeff Garzik break; 2666c6fd2807SJeff Garzik } 2667c6fd2807SJeff Garzik break; 2668c6fd2807SJeff Garzik 2669c6fd2807SJeff Garzik case chip_604x: 2670c6fd2807SJeff Garzik case chip_608x: 2671c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2672ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_II; 2673c6fd2807SJeff Garzik 267444c10138SAuke Kok switch (pdev->revision) { 2675c6fd2807SJeff Garzik case 0x7: 2676c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2677c6fd2807SJeff Garzik break; 2678c6fd2807SJeff Garzik case 0x9: 2679c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2680c6fd2807SJeff Garzik break; 2681c6fd2807SJeff Garzik default: 2682c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2683c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2684c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2685c6fd2807SJeff Garzik break; 2686c6fd2807SJeff Garzik } 2687c6fd2807SJeff Garzik break; 2688c6fd2807SJeff Garzik 2689c6fd2807SJeff Garzik case chip_7042: 269002a121daSMark Lord hp_flags |= MV_HP_PCIE; 2691306b30f7SMark Lord if (pdev->vendor == PCI_VENDOR_ID_TTI && 2692306b30f7SMark Lord (pdev->device == 0x2300 || pdev->device == 0x2310)) 2693306b30f7SMark Lord { 26944e520033SMark Lord /* 26954e520033SMark Lord * Highpoint RocketRAID PCIe 23xx series cards: 26964e520033SMark Lord * 26974e520033SMark Lord * Unconfigured drives are treated as "Legacy" 26984e520033SMark Lord * by the BIOS, and it overwrites sector 8 with 26994e520033SMark Lord * a "Lgcy" metadata block prior to Linux boot. 27004e520033SMark Lord * 27014e520033SMark Lord * Configured drives (RAID or JBOD) leave sector 8 27024e520033SMark Lord * alone, but instead overwrite a high numbered 27034e520033SMark Lord * sector for the RAID metadata. This sector can 27044e520033SMark Lord * be determined exactly, by truncating the physical 27054e520033SMark Lord * drive capacity to a nice even GB value. 27064e520033SMark Lord * 27074e520033SMark Lord * RAID metadata is at: (dev->n_sectors & ~0xfffff) 27084e520033SMark Lord * 27094e520033SMark Lord * Warn the user, lest they think we're just buggy. 27104e520033SMark Lord */ 27114e520033SMark Lord printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID" 27124e520033SMark Lord " BIOS CORRUPTS DATA on all attached drives," 27134e520033SMark Lord " regardless of if/how they are configured." 27144e520033SMark Lord " BEWARE!\n"); 27154e520033SMark Lord printk(KERN_WARNING DRV_NAME ": For data safety, do not" 27164e520033SMark Lord " use sectors 8-9 on \"Legacy\" drives," 27174e520033SMark Lord " and avoid the final two gigabytes on" 27184e520033SMark Lord " all RocketRAID BIOS initialized drives.\n"); 2719306b30f7SMark Lord } 2720c6fd2807SJeff Garzik case chip_6042: 2721c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2722c6fd2807SJeff Garzik hp_flags |= MV_HP_GEN_IIE; 2723c6fd2807SJeff Garzik 272444c10138SAuke Kok switch (pdev->revision) { 2725c6fd2807SJeff Garzik case 0x0: 2726c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_XX42A0; 2727c6fd2807SJeff Garzik break; 2728c6fd2807SJeff Garzik case 0x1: 2729c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2730c6fd2807SJeff Garzik break; 2731c6fd2807SJeff Garzik default: 2732c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2733c6fd2807SJeff Garzik "Applying 60X1C0 workarounds to unknown rev\n"); 2734c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2735c6fd2807SJeff Garzik break; 2736c6fd2807SJeff Garzik } 2737c6fd2807SJeff Garzik break; 2738f351b2d6SSaeed Bishara case chip_soc: 2739f351b2d6SSaeed Bishara hpriv->ops = &mv_soc_ops; 2740f351b2d6SSaeed Bishara hp_flags |= MV_HP_ERRATA_60X1C0; 2741f351b2d6SSaeed Bishara break; 2742c6fd2807SJeff Garzik 2743c6fd2807SJeff Garzik default: 2744f351b2d6SSaeed Bishara dev_printk(KERN_ERR, host->dev, 27455796d1c4SJeff Garzik "BUG: invalid board index %u\n", board_idx); 2746c6fd2807SJeff Garzik return 1; 2747c6fd2807SJeff Garzik } 2748c6fd2807SJeff Garzik 2749c6fd2807SJeff Garzik hpriv->hp_flags = hp_flags; 275002a121daSMark Lord if (hp_flags & MV_HP_PCIE) { 275102a121daSMark Lord hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS; 275202a121daSMark Lord hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS; 275302a121daSMark Lord hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS; 275402a121daSMark Lord } else { 275502a121daSMark Lord hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS; 275602a121daSMark Lord hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS; 275702a121daSMark Lord hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS; 275802a121daSMark Lord } 2759c6fd2807SJeff Garzik 2760c6fd2807SJeff Garzik return 0; 2761c6fd2807SJeff Garzik } 2762c6fd2807SJeff Garzik 2763c6fd2807SJeff Garzik /** 2764c6fd2807SJeff Garzik * mv_init_host - Perform some early initialization of the host. 27654447d351STejun Heo * @host: ATA host to initialize 27664447d351STejun Heo * @board_idx: controller index 2767c6fd2807SJeff Garzik * 2768c6fd2807SJeff Garzik * If possible, do an early global reset of the host. Then do 2769c6fd2807SJeff Garzik * our port init and clear/unmask all/relevant host interrupts. 2770c6fd2807SJeff Garzik * 2771c6fd2807SJeff Garzik * LOCKING: 2772c6fd2807SJeff Garzik * Inherited from caller. 2773c6fd2807SJeff Garzik */ 27744447d351STejun Heo static int mv_init_host(struct ata_host *host, unsigned int board_idx) 2775c6fd2807SJeff Garzik { 2776c6fd2807SJeff Garzik int rc = 0, n_hc, port, hc; 27774447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2778f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2779c6fd2807SJeff Garzik 27804447d351STejun Heo rc = mv_chip_id(host, board_idx); 2781c6fd2807SJeff Garzik if (rc) 2782c6fd2807SJeff Garzik goto done; 2783c6fd2807SJeff Garzik 2784f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2785f351b2d6SSaeed Bishara hpriv->main_cause_reg_addr = hpriv->base + 2786f351b2d6SSaeed Bishara HC_MAIN_IRQ_CAUSE_OFS; 2787f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr = hpriv->base + HC_MAIN_IRQ_MASK_OFS; 2788f351b2d6SSaeed Bishara } else { 2789f351b2d6SSaeed Bishara hpriv->main_cause_reg_addr = hpriv->base + 2790f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_CAUSE_OFS; 2791f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr = hpriv->base + 2792f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_MASK_OFS; 2793f351b2d6SSaeed Bishara } 2794f351b2d6SSaeed Bishara /* global interrupt mask */ 2795f351b2d6SSaeed Bishara writel(0, hpriv->main_mask_reg_addr); 2796f351b2d6SSaeed Bishara 27974447d351STejun Heo n_hc = mv_get_hc_count(host->ports[0]->flags); 2798c6fd2807SJeff Garzik 27994447d351STejun Heo for (port = 0; port < host->n_ports; port++) 2800c6fd2807SJeff Garzik hpriv->ops->read_preamp(hpriv, port, mmio); 2801c6fd2807SJeff Garzik 2802c6fd2807SJeff Garzik rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 2803c6fd2807SJeff Garzik if (rc) 2804c6fd2807SJeff Garzik goto done; 2805c6fd2807SJeff Garzik 2806c6fd2807SJeff Garzik hpriv->ops->reset_flash(hpriv, mmio); 28077bb3c529SSaeed Bishara hpriv->ops->reset_bus(host, mmio); 2808c6fd2807SJeff Garzik hpriv->ops->enable_leds(hpriv, mmio); 2809c6fd2807SJeff Garzik 28104447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2811ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2812c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2813c6fd2807SJeff Garzik 2814c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2815c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2816c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2817c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2818c6fd2807SJeff Garzik } 2819c6fd2807SJeff Garzik 2820c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port); 2821c6fd2807SJeff Garzik } 2822c6fd2807SJeff Garzik 28234447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2824cbcdd875STejun Heo struct ata_port *ap = host->ports[port]; 2825c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2826cbcdd875STejun Heo 2827cbcdd875STejun Heo mv_port_init(&ap->ioaddr, port_mmio); 2828cbcdd875STejun Heo 28297bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2830f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2831f351b2d6SSaeed Bishara unsigned int offset = port_mmio - mmio; 2832cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio"); 2833cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port"); 2834f351b2d6SSaeed Bishara } 28357bb3c529SSaeed Bishara #endif 2836c6fd2807SJeff Garzik } 2837c6fd2807SJeff Garzik 2838c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 2839c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2840c6fd2807SJeff Garzik 2841c6fd2807SJeff Garzik VPRINTK("HC%i: HC config=0x%08x HC IRQ cause " 2842c6fd2807SJeff Garzik "(before clear)=0x%08x\n", hc, 2843c6fd2807SJeff Garzik readl(hc_mmio + HC_CFG_OFS), 2844c6fd2807SJeff Garzik readl(hc_mmio + HC_IRQ_CAUSE_OFS)); 2845c6fd2807SJeff Garzik 2846c6fd2807SJeff Garzik /* Clear any currently outstanding hc interrupt conditions */ 2847c6fd2807SJeff Garzik writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS); 2848c6fd2807SJeff Garzik } 2849c6fd2807SJeff Garzik 2850f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2851c6fd2807SJeff Garzik /* Clear any currently outstanding host interrupt conditions */ 285202a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 2853c6fd2807SJeff Garzik 2854c6fd2807SJeff Garzik /* and unmask interrupt generation for host regs */ 285502a121daSMark Lord writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs); 2856ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2857f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS_5, 2858f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2859fb621e2fSJeff Garzik else 2860f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS, 2861f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2862c6fd2807SJeff Garzik 2863c6fd2807SJeff Garzik VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 2864c6fd2807SJeff Garzik "PCI int cause/mask=0x%08x/0x%08x\n", 2865f351b2d6SSaeed Bishara readl(hpriv->main_cause_reg_addr), 2866f351b2d6SSaeed Bishara readl(hpriv->main_mask_reg_addr), 286702a121daSMark Lord readl(mmio + hpriv->irq_cause_ofs), 286802a121daSMark Lord readl(mmio + hpriv->irq_mask_ofs)); 2869f351b2d6SSaeed Bishara } else { 2870f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS_SOC, 2871f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2872f351b2d6SSaeed Bishara VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x\n", 2873f351b2d6SSaeed Bishara readl(hpriv->main_cause_reg_addr), 2874f351b2d6SSaeed Bishara readl(hpriv->main_mask_reg_addr)); 2875f351b2d6SSaeed Bishara } 2876c6fd2807SJeff Garzik done: 2877c6fd2807SJeff Garzik return rc; 2878c6fd2807SJeff Garzik } 2879c6fd2807SJeff Garzik 2880fbf14e2fSByron Bradley static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev) 2881fbf14e2fSByron Bradley { 2882fbf14e2fSByron Bradley hpriv->crqb_pool = dmam_pool_create("crqb_q", dev, MV_CRQB_Q_SZ, 2883fbf14e2fSByron Bradley MV_CRQB_Q_SZ, 0); 2884fbf14e2fSByron Bradley if (!hpriv->crqb_pool) 2885fbf14e2fSByron Bradley return -ENOMEM; 2886fbf14e2fSByron Bradley 2887fbf14e2fSByron Bradley hpriv->crpb_pool = dmam_pool_create("crpb_q", dev, MV_CRPB_Q_SZ, 2888fbf14e2fSByron Bradley MV_CRPB_Q_SZ, 0); 2889fbf14e2fSByron Bradley if (!hpriv->crpb_pool) 2890fbf14e2fSByron Bradley return -ENOMEM; 2891fbf14e2fSByron Bradley 2892fbf14e2fSByron Bradley hpriv->sg_tbl_pool = dmam_pool_create("sg_tbl", dev, MV_SG_TBL_SZ, 2893fbf14e2fSByron Bradley MV_SG_TBL_SZ, 0); 2894fbf14e2fSByron Bradley if (!hpriv->sg_tbl_pool) 2895fbf14e2fSByron Bradley return -ENOMEM; 2896fbf14e2fSByron Bradley 2897fbf14e2fSByron Bradley return 0; 2898fbf14e2fSByron Bradley } 2899fbf14e2fSByron Bradley 2900f351b2d6SSaeed Bishara /** 2901f351b2d6SSaeed Bishara * mv_platform_probe - handle a positive probe of an soc Marvell 2902f351b2d6SSaeed Bishara * host 2903f351b2d6SSaeed Bishara * @pdev: platform device found 2904f351b2d6SSaeed Bishara * 2905f351b2d6SSaeed Bishara * LOCKING: 2906f351b2d6SSaeed Bishara * Inherited from caller. 2907f351b2d6SSaeed Bishara */ 2908f351b2d6SSaeed Bishara static int mv_platform_probe(struct platform_device *pdev) 2909f351b2d6SSaeed Bishara { 2910f351b2d6SSaeed Bishara static int printed_version; 2911f351b2d6SSaeed Bishara const struct mv_sata_platform_data *mv_platform_data; 2912f351b2d6SSaeed Bishara const struct ata_port_info *ppi[] = 2913f351b2d6SSaeed Bishara { &mv_port_info[chip_soc], NULL }; 2914f351b2d6SSaeed Bishara struct ata_host *host; 2915f351b2d6SSaeed Bishara struct mv_host_priv *hpriv; 2916f351b2d6SSaeed Bishara struct resource *res; 2917f351b2d6SSaeed Bishara int n_ports, rc; 2918f351b2d6SSaeed Bishara 2919f351b2d6SSaeed Bishara if (!printed_version++) 2920f351b2d6SSaeed Bishara dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2921f351b2d6SSaeed Bishara 2922f351b2d6SSaeed Bishara /* 2923f351b2d6SSaeed Bishara * Simple resource validation .. 2924f351b2d6SSaeed Bishara */ 2925f351b2d6SSaeed Bishara if (unlikely(pdev->num_resources != 2)) { 2926f351b2d6SSaeed Bishara dev_err(&pdev->dev, "invalid number of resources\n"); 2927f351b2d6SSaeed Bishara return -EINVAL; 2928f351b2d6SSaeed Bishara } 2929f351b2d6SSaeed Bishara 2930f351b2d6SSaeed Bishara /* 2931f351b2d6SSaeed Bishara * Get the register base first 2932f351b2d6SSaeed Bishara */ 2933f351b2d6SSaeed Bishara res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2934f351b2d6SSaeed Bishara if (res == NULL) 2935f351b2d6SSaeed Bishara return -EINVAL; 2936f351b2d6SSaeed Bishara 2937f351b2d6SSaeed Bishara /* allocate host */ 2938f351b2d6SSaeed Bishara mv_platform_data = pdev->dev.platform_data; 2939f351b2d6SSaeed Bishara n_ports = mv_platform_data->n_ports; 2940f351b2d6SSaeed Bishara 2941f351b2d6SSaeed Bishara host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 2942f351b2d6SSaeed Bishara hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 2943f351b2d6SSaeed Bishara 2944f351b2d6SSaeed Bishara if (!host || !hpriv) 2945f351b2d6SSaeed Bishara return -ENOMEM; 2946f351b2d6SSaeed Bishara host->private_data = hpriv; 2947f351b2d6SSaeed Bishara hpriv->n_ports = n_ports; 2948f351b2d6SSaeed Bishara 2949f351b2d6SSaeed Bishara host->iomap = NULL; 2950f351b2d6SSaeed Bishara hpriv->base = ioremap(res->start, res->end - res->start + 1); 2951f351b2d6SSaeed Bishara hpriv->base -= MV_SATAHC0_REG_BASE; 2952f351b2d6SSaeed Bishara 2953fbf14e2fSByron Bradley rc = mv_create_dma_pools(hpriv, &pdev->dev); 2954fbf14e2fSByron Bradley if (rc) 2955fbf14e2fSByron Bradley return rc; 2956fbf14e2fSByron Bradley 2957f351b2d6SSaeed Bishara /* initialize adapter */ 2958f351b2d6SSaeed Bishara rc = mv_init_host(host, chip_soc); 2959f351b2d6SSaeed Bishara if (rc) 2960f351b2d6SSaeed Bishara return rc; 2961f351b2d6SSaeed Bishara 2962f351b2d6SSaeed Bishara dev_printk(KERN_INFO, &pdev->dev, 2963f351b2d6SSaeed Bishara "slots %u ports %d\n", (unsigned)MV_MAX_Q_DEPTH, 2964f351b2d6SSaeed Bishara host->n_ports); 2965f351b2d6SSaeed Bishara 2966f351b2d6SSaeed Bishara return ata_host_activate(host, platform_get_irq(pdev, 0), mv_interrupt, 2967f351b2d6SSaeed Bishara IRQF_SHARED, &mv6_sht); 2968f351b2d6SSaeed Bishara } 2969f351b2d6SSaeed Bishara 2970f351b2d6SSaeed Bishara /* 2971f351b2d6SSaeed Bishara * 2972f351b2d6SSaeed Bishara * mv_platform_remove - unplug a platform interface 2973f351b2d6SSaeed Bishara * @pdev: platform device 2974f351b2d6SSaeed Bishara * 2975f351b2d6SSaeed Bishara * A platform bus SATA device has been unplugged. Perform the needed 2976f351b2d6SSaeed Bishara * cleanup. Also called on module unload for any active devices. 2977f351b2d6SSaeed Bishara */ 2978f351b2d6SSaeed Bishara static int __devexit mv_platform_remove(struct platform_device *pdev) 2979f351b2d6SSaeed Bishara { 2980f351b2d6SSaeed Bishara struct device *dev = &pdev->dev; 2981f351b2d6SSaeed Bishara struct ata_host *host = dev_get_drvdata(dev); 2982f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 2983f351b2d6SSaeed Bishara void __iomem *base = hpriv->base; 2984f351b2d6SSaeed Bishara 2985f351b2d6SSaeed Bishara ata_host_detach(host); 2986f351b2d6SSaeed Bishara iounmap(base); 2987f351b2d6SSaeed Bishara return 0; 2988f351b2d6SSaeed Bishara } 2989f351b2d6SSaeed Bishara 2990f351b2d6SSaeed Bishara static struct platform_driver mv_platform_driver = { 2991f351b2d6SSaeed Bishara .probe = mv_platform_probe, 2992f351b2d6SSaeed Bishara .remove = __devexit_p(mv_platform_remove), 2993f351b2d6SSaeed Bishara .driver = { 2994f351b2d6SSaeed Bishara .name = DRV_NAME, 2995f351b2d6SSaeed Bishara .owner = THIS_MODULE, 2996f351b2d6SSaeed Bishara }, 2997f351b2d6SSaeed Bishara }; 2998f351b2d6SSaeed Bishara 2999f351b2d6SSaeed Bishara 30007bb3c529SSaeed Bishara #ifdef CONFIG_PCI 3001f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 3002f351b2d6SSaeed Bishara const struct pci_device_id *ent); 3003f351b2d6SSaeed Bishara 30047bb3c529SSaeed Bishara 30057bb3c529SSaeed Bishara static struct pci_driver mv_pci_driver = { 30067bb3c529SSaeed Bishara .name = DRV_NAME, 30077bb3c529SSaeed Bishara .id_table = mv_pci_tbl, 3008f351b2d6SSaeed Bishara .probe = mv_pci_init_one, 30097bb3c529SSaeed Bishara .remove = ata_pci_remove_one, 30107bb3c529SSaeed Bishara }; 30117bb3c529SSaeed Bishara 30127bb3c529SSaeed Bishara /* 30137bb3c529SSaeed Bishara * module options 30147bb3c529SSaeed Bishara */ 30157bb3c529SSaeed Bishara static int msi; /* Use PCI msi; either zero (off, default) or non-zero */ 30167bb3c529SSaeed Bishara 30177bb3c529SSaeed Bishara 30187bb3c529SSaeed Bishara /* move to PCI layer or libata core? */ 30197bb3c529SSaeed Bishara static int pci_go_64(struct pci_dev *pdev) 30207bb3c529SSaeed Bishara { 30217bb3c529SSaeed Bishara int rc; 30227bb3c529SSaeed Bishara 30237bb3c529SSaeed Bishara if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 30247bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 30257bb3c529SSaeed Bishara if (rc) { 30267bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 30277bb3c529SSaeed Bishara if (rc) { 30287bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 30297bb3c529SSaeed Bishara "64-bit DMA enable failed\n"); 30307bb3c529SSaeed Bishara return rc; 30317bb3c529SSaeed Bishara } 30327bb3c529SSaeed Bishara } 30337bb3c529SSaeed Bishara } else { 30347bb3c529SSaeed Bishara rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 30357bb3c529SSaeed Bishara if (rc) { 30367bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 30377bb3c529SSaeed Bishara "32-bit DMA enable failed\n"); 30387bb3c529SSaeed Bishara return rc; 30397bb3c529SSaeed Bishara } 30407bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 30417bb3c529SSaeed Bishara if (rc) { 30427bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 30437bb3c529SSaeed Bishara "32-bit consistent DMA enable failed\n"); 30447bb3c529SSaeed Bishara return rc; 30457bb3c529SSaeed Bishara } 30467bb3c529SSaeed Bishara } 30477bb3c529SSaeed Bishara 30487bb3c529SSaeed Bishara return rc; 30497bb3c529SSaeed Bishara } 30507bb3c529SSaeed Bishara 3051c6fd2807SJeff Garzik /** 3052c6fd2807SJeff Garzik * mv_print_info - Dump key info to kernel log for perusal. 30534447d351STejun Heo * @host: ATA host to print info about 3054c6fd2807SJeff Garzik * 3055c6fd2807SJeff Garzik * FIXME: complete this. 3056c6fd2807SJeff Garzik * 3057c6fd2807SJeff Garzik * LOCKING: 3058c6fd2807SJeff Garzik * Inherited from caller. 3059c6fd2807SJeff Garzik */ 30604447d351STejun Heo static void mv_print_info(struct ata_host *host) 3061c6fd2807SJeff Garzik { 30624447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 30634447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 306444c10138SAuke Kok u8 scc; 3065c1e4fe71SJeff Garzik const char *scc_s, *gen; 3066c6fd2807SJeff Garzik 3067c6fd2807SJeff Garzik /* Use this to determine the HW stepping of the chip so we know 3068c6fd2807SJeff Garzik * what errata to workaround 3069c6fd2807SJeff Garzik */ 3070c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc); 3071c6fd2807SJeff Garzik if (scc == 0) 3072c6fd2807SJeff Garzik scc_s = "SCSI"; 3073c6fd2807SJeff Garzik else if (scc == 0x01) 3074c6fd2807SJeff Garzik scc_s = "RAID"; 3075c6fd2807SJeff Garzik else 3076c1e4fe71SJeff Garzik scc_s = "?"; 3077c1e4fe71SJeff Garzik 3078c1e4fe71SJeff Garzik if (IS_GEN_I(hpriv)) 3079c1e4fe71SJeff Garzik gen = "I"; 3080c1e4fe71SJeff Garzik else if (IS_GEN_II(hpriv)) 3081c1e4fe71SJeff Garzik gen = "II"; 3082c1e4fe71SJeff Garzik else if (IS_GEN_IIE(hpriv)) 3083c1e4fe71SJeff Garzik gen = "IIE"; 3084c1e4fe71SJeff Garzik else 3085c1e4fe71SJeff Garzik gen = "?"; 3086c6fd2807SJeff Garzik 3087c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, 3088c1e4fe71SJeff Garzik "Gen-%s %u slots %u ports %s mode IRQ via %s\n", 3089c1e4fe71SJeff Garzik gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports, 3090c6fd2807SJeff Garzik scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 3091c6fd2807SJeff Garzik } 3092c6fd2807SJeff Garzik 3093c6fd2807SJeff Garzik /** 3094f351b2d6SSaeed Bishara * mv_pci_init_one - handle a positive probe of a PCI Marvell host 3095c6fd2807SJeff Garzik * @pdev: PCI device found 3096c6fd2807SJeff Garzik * @ent: PCI device ID entry for the matched host 3097c6fd2807SJeff Garzik * 3098c6fd2807SJeff Garzik * LOCKING: 3099c6fd2807SJeff Garzik * Inherited from caller. 3100c6fd2807SJeff Garzik */ 3101f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 3102f351b2d6SSaeed Bishara const struct pci_device_id *ent) 3103c6fd2807SJeff Garzik { 31042dcb407eSJeff Garzik static int printed_version; 3105c6fd2807SJeff Garzik unsigned int board_idx = (unsigned int)ent->driver_data; 31064447d351STejun Heo const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL }; 31074447d351STejun Heo struct ata_host *host; 31084447d351STejun Heo struct mv_host_priv *hpriv; 31094447d351STejun Heo int n_ports, rc; 3110c6fd2807SJeff Garzik 3111c6fd2807SJeff Garzik if (!printed_version++) 3112c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 3113c6fd2807SJeff Garzik 31144447d351STejun Heo /* allocate host */ 31154447d351STejun Heo n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC; 31164447d351STejun Heo 31174447d351STejun Heo host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 31184447d351STejun Heo hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 31194447d351STejun Heo if (!host || !hpriv) 31204447d351STejun Heo return -ENOMEM; 31214447d351STejun Heo host->private_data = hpriv; 3122f351b2d6SSaeed Bishara hpriv->n_ports = n_ports; 31234447d351STejun Heo 31244447d351STejun Heo /* acquire resources */ 312524dc5f33STejun Heo rc = pcim_enable_device(pdev); 312624dc5f33STejun Heo if (rc) 3127c6fd2807SJeff Garzik return rc; 3128c6fd2807SJeff Garzik 31290d5ff566STejun Heo rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 31300d5ff566STejun Heo if (rc == -EBUSY) 313124dc5f33STejun Heo pcim_pin_device(pdev); 31320d5ff566STejun Heo if (rc) 313324dc5f33STejun Heo return rc; 31344447d351STejun Heo host->iomap = pcim_iomap_table(pdev); 3135f351b2d6SSaeed Bishara hpriv->base = host->iomap[MV_PRIMARY_BAR]; 3136c6fd2807SJeff Garzik 3137d88184fbSJeff Garzik rc = pci_go_64(pdev); 3138d88184fbSJeff Garzik if (rc) 3139d88184fbSJeff Garzik return rc; 3140d88184fbSJeff Garzik 3141da2fa9baSMark Lord rc = mv_create_dma_pools(hpriv, &pdev->dev); 3142da2fa9baSMark Lord if (rc) 3143da2fa9baSMark Lord return rc; 3144da2fa9baSMark Lord 3145c6fd2807SJeff Garzik /* initialize adapter */ 31464447d351STejun Heo rc = mv_init_host(host, board_idx); 314724dc5f33STejun Heo if (rc) 314824dc5f33STejun Heo return rc; 3149c6fd2807SJeff Garzik 3150c6fd2807SJeff Garzik /* Enable interrupts */ 31516a59dcf8STejun Heo if (msi && pci_enable_msi(pdev)) 3152c6fd2807SJeff Garzik pci_intx(pdev, 1); 3153c6fd2807SJeff Garzik 3154c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 31554447d351STejun Heo mv_print_info(host); 3156c6fd2807SJeff Garzik 31574447d351STejun Heo pci_set_master(pdev); 3158ea8b4db9SJeff Garzik pci_try_set_mwi(pdev); 31594447d351STejun Heo return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, 3160c5d3e45aSJeff Garzik IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht); 3161c6fd2807SJeff Garzik } 31627bb3c529SSaeed Bishara #endif 3163c6fd2807SJeff Garzik 3164f351b2d6SSaeed Bishara static int mv_platform_probe(struct platform_device *pdev); 3165f351b2d6SSaeed Bishara static int __devexit mv_platform_remove(struct platform_device *pdev); 3166f351b2d6SSaeed Bishara 3167c6fd2807SJeff Garzik static int __init mv_init(void) 3168c6fd2807SJeff Garzik { 31697bb3c529SSaeed Bishara int rc = -ENODEV; 31707bb3c529SSaeed Bishara #ifdef CONFIG_PCI 31717bb3c529SSaeed Bishara rc = pci_register_driver(&mv_pci_driver); 3172f351b2d6SSaeed Bishara if (rc < 0) 3173f351b2d6SSaeed Bishara return rc; 3174f351b2d6SSaeed Bishara #endif 3175f351b2d6SSaeed Bishara rc = platform_driver_register(&mv_platform_driver); 3176f351b2d6SSaeed Bishara 3177f351b2d6SSaeed Bishara #ifdef CONFIG_PCI 3178f351b2d6SSaeed Bishara if (rc < 0) 3179f351b2d6SSaeed Bishara pci_unregister_driver(&mv_pci_driver); 31807bb3c529SSaeed Bishara #endif 31817bb3c529SSaeed Bishara return rc; 3182c6fd2807SJeff Garzik } 3183c6fd2807SJeff Garzik 3184c6fd2807SJeff Garzik static void __exit mv_exit(void) 3185c6fd2807SJeff Garzik { 31867bb3c529SSaeed Bishara #ifdef CONFIG_PCI 3187c6fd2807SJeff Garzik pci_unregister_driver(&mv_pci_driver); 31887bb3c529SSaeed Bishara #endif 3189f351b2d6SSaeed Bishara platform_driver_unregister(&mv_platform_driver); 3190c6fd2807SJeff Garzik } 3191c6fd2807SJeff Garzik 3192c6fd2807SJeff Garzik MODULE_AUTHOR("Brett Russ"); 3193c6fd2807SJeff Garzik MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers"); 3194c6fd2807SJeff Garzik MODULE_LICENSE("GPL"); 3195c6fd2807SJeff Garzik MODULE_DEVICE_TABLE(pci, mv_pci_tbl); 3196c6fd2807SJeff Garzik MODULE_VERSION(DRV_VERSION); 3197c6fd2807SJeff Garzik 31987bb3c529SSaeed Bishara #ifdef CONFIG_PCI 3199c6fd2807SJeff Garzik module_param(msi, int, 0444); 3200c6fd2807SJeff Garzik MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)"); 32017bb3c529SSaeed Bishara #endif 3202c6fd2807SJeff Garzik 3203c6fd2807SJeff Garzik module_init(mv_init); 3204c6fd2807SJeff Garzik module_exit(mv_exit); 3205