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 464da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 465da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 466da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 467da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 468c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap); 469c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap); 470c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc); 471c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 472c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 473bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap); 474bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap); 475bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap); 476f273827eSMark Lord static void mv6_dev_config(struct ata_device *dev); 477c6fd2807SJeff Garzik 478c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 479c6fd2807SJeff Garzik unsigned int port); 480c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 481c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 482c6fd2807SJeff Garzik void __iomem *mmio); 483c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 484c6fd2807SJeff Garzik unsigned int n_hc); 485c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 4867bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio); 487c6fd2807SJeff Garzik 488c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 489c6fd2807SJeff Garzik unsigned int port); 490c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 491c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 492c6fd2807SJeff Garzik void __iomem *mmio); 493c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 494c6fd2807SJeff Garzik unsigned int n_hc); 495c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 496f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 497f351b2d6SSaeed Bishara void __iomem *mmio); 498f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 499f351b2d6SSaeed Bishara void __iomem *mmio); 500f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 501f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc); 502f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 503f351b2d6SSaeed Bishara void __iomem *mmio); 504f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio); 5057bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio); 506c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 507c6fd2807SJeff Garzik unsigned int port_no); 50872109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 50972109168SMark Lord void __iomem *port_mmio, int want_ncq); 51072109168SMark Lord static int __mv_stop_dma(struct ata_port *ap); 511c6fd2807SJeff Garzik 512eb73d558SMark Lord /* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below 513eb73d558SMark Lord * because we have to allow room for worst case splitting of 514eb73d558SMark Lord * PRDs for 64K boundaries in mv_fill_sg(). 515eb73d558SMark Lord */ 516c5d3e45aSJeff Garzik static struct scsi_host_template mv5_sht = { 517*68d1d07bSTejun Heo ATA_BASE_SHT(DRV_NAME), 518baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 519c5d3e45aSJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 520c5d3e45aSJeff Garzik }; 521c5d3e45aSJeff Garzik 522c5d3e45aSJeff Garzik static struct scsi_host_template mv6_sht = { 523*68d1d07bSTejun Heo ATA_NCQ_SHT(DRV_NAME), 524138bfdd0SMark Lord .can_queue = MV_MAX_Q_DEPTH - 1, 525baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 526c6fd2807SJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 527c6fd2807SJeff Garzik }; 528c6fd2807SJeff Garzik 529c6fd2807SJeff Garzik static const struct ata_port_operations mv5_ops = { 530c6fd2807SJeff Garzik .tf_load = ata_tf_load, 531c6fd2807SJeff Garzik .tf_read = ata_tf_read, 532c6fd2807SJeff Garzik .check_status = ata_check_status, 533c6fd2807SJeff Garzik .exec_command = ata_exec_command, 534c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 535c6fd2807SJeff Garzik 536c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 537c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5380d5ff566STejun Heo .data_xfer = ata_data_xfer, 539c6fd2807SJeff Garzik 540358f9a77STejun Heo .irq_clear = ata_noop_irq_clear, 541246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 542c6fd2807SJeff Garzik 543bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 544bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 545bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 546bdd4dddeSJeff Garzik 547c6fd2807SJeff Garzik .scr_read = mv5_scr_read, 548c6fd2807SJeff Garzik .scr_write = mv5_scr_write, 549c6fd2807SJeff Garzik 550c6fd2807SJeff Garzik .port_start = mv_port_start, 551c6fd2807SJeff Garzik .port_stop = mv_port_stop, 552c6fd2807SJeff Garzik }; 553c6fd2807SJeff Garzik 554c6fd2807SJeff Garzik static const struct ata_port_operations mv6_ops = { 555f273827eSMark Lord .dev_config = mv6_dev_config, 556c6fd2807SJeff Garzik .tf_load = ata_tf_load, 557c6fd2807SJeff Garzik .tf_read = ata_tf_read, 558c6fd2807SJeff Garzik .check_status = ata_check_status, 559c6fd2807SJeff Garzik .exec_command = ata_exec_command, 560c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 561c6fd2807SJeff Garzik 562c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 563c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5640d5ff566STejun Heo .data_xfer = ata_data_xfer, 565c6fd2807SJeff Garzik 566358f9a77STejun Heo .irq_clear = ata_noop_irq_clear, 567246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 568c6fd2807SJeff Garzik 569bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 570bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 571bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 572138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 573bdd4dddeSJeff Garzik 574c6fd2807SJeff Garzik .scr_read = mv_scr_read, 575c6fd2807SJeff Garzik .scr_write = mv_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 mv_iie_ops = { 582c6fd2807SJeff Garzik .tf_load = ata_tf_load, 583c6fd2807SJeff Garzik .tf_read = ata_tf_read, 584c6fd2807SJeff Garzik .check_status = ata_check_status, 585c6fd2807SJeff Garzik .exec_command = ata_exec_command, 586c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 587c6fd2807SJeff Garzik 588c6fd2807SJeff Garzik .qc_prep = mv_qc_prep_iie, 589c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5900d5ff566STejun Heo .data_xfer = ata_data_xfer, 591c6fd2807SJeff Garzik 592358f9a77STejun Heo .irq_clear = ata_noop_irq_clear, 593246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 594c6fd2807SJeff Garzik 595bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 596bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 597bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 598138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 599bdd4dddeSJeff Garzik 600c6fd2807SJeff Garzik .scr_read = mv_scr_read, 601c6fd2807SJeff Garzik .scr_write = mv_scr_write, 602c6fd2807SJeff Garzik 603c6fd2807SJeff Garzik .port_start = mv_port_start, 604c6fd2807SJeff Garzik .port_stop = mv_port_stop, 605c6fd2807SJeff Garzik }; 606c6fd2807SJeff Garzik 607c6fd2807SJeff Garzik static const struct ata_port_info mv_port_info[] = { 608c6fd2807SJeff Garzik { /* chip_504x */ 609cca3974eSJeff Garzik .flags = MV_COMMON_FLAGS, 610c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 611bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 612c6fd2807SJeff Garzik .port_ops = &mv5_ops, 613c6fd2807SJeff Garzik }, 614c6fd2807SJeff Garzik { /* chip_508x */ 615c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 616c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 617bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 618c6fd2807SJeff Garzik .port_ops = &mv5_ops, 619c6fd2807SJeff Garzik }, 620c6fd2807SJeff Garzik { /* chip_5080 */ 621c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 622c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 623bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 624c6fd2807SJeff Garzik .port_ops = &mv5_ops, 625c6fd2807SJeff Garzik }, 626c6fd2807SJeff Garzik { /* chip_604x */ 627138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 628138bfdd0SMark Lord ATA_FLAG_NCQ, 629c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 630bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 631c6fd2807SJeff Garzik .port_ops = &mv6_ops, 632c6fd2807SJeff Garzik }, 633c6fd2807SJeff Garzik { /* chip_608x */ 634c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 635138bfdd0SMark Lord ATA_FLAG_NCQ | MV_FLAG_DUAL_HC, 636c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 637bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 638c6fd2807SJeff Garzik .port_ops = &mv6_ops, 639c6fd2807SJeff Garzik }, 640c6fd2807SJeff Garzik { /* chip_6042 */ 641138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 642138bfdd0SMark Lord ATA_FLAG_NCQ, 643c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 644bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 645c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 646c6fd2807SJeff Garzik }, 647c6fd2807SJeff Garzik { /* chip_7042 */ 648138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 649138bfdd0SMark Lord ATA_FLAG_NCQ, 650c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 651bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 652c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 653c6fd2807SJeff Garzik }, 654f351b2d6SSaeed Bishara { /* chip_soc */ 655f351b2d6SSaeed Bishara .flags = MV_COMMON_FLAGS | MV_FLAG_SOC, 656f351b2d6SSaeed Bishara .pio_mask = 0x1f, /* pio0-4 */ 657f351b2d6SSaeed Bishara .udma_mask = ATA_UDMA6, 658f351b2d6SSaeed Bishara .port_ops = &mv_iie_ops, 659f351b2d6SSaeed Bishara }, 660c6fd2807SJeff Garzik }; 661c6fd2807SJeff Garzik 662c6fd2807SJeff Garzik static const struct pci_device_id mv_pci_tbl[] = { 6632d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5040), chip_504x }, 6642d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 6652d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 6662d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 667cfbf723eSAlan Cox /* RocketRAID 1740/174x have different identifiers */ 668cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1740), chip_508x }, 669cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1742), chip_508x }, 670c6fd2807SJeff Garzik 6712d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6040), chip_604x }, 6722d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6041), chip_604x }, 6732d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 }, 6742d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6080), chip_608x }, 6752d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6081), chip_608x }, 676c6fd2807SJeff Garzik 6772d2744fcSJeff Garzik { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 6782d2744fcSJeff Garzik 679d9f9c6bcSFlorian Attenberger /* Adaptec 1430SA */ 680d9f9c6bcSFlorian Attenberger { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 }, 681d9f9c6bcSFlorian Attenberger 68202a121daSMark Lord /* Marvell 7042 support */ 6836a3d586dSMorrison, Tom { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 }, 6846a3d586dSMorrison, Tom 68502a121daSMark Lord /* Highpoint RocketRAID PCIe series */ 68602a121daSMark Lord { PCI_VDEVICE(TTI, 0x2300), chip_7042 }, 68702a121daSMark Lord { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 68802a121daSMark Lord 689c6fd2807SJeff Garzik { } /* terminate list */ 690c6fd2807SJeff Garzik }; 691c6fd2807SJeff Garzik 692c6fd2807SJeff Garzik static const struct mv_hw_ops mv5xxx_ops = { 693c6fd2807SJeff Garzik .phy_errata = mv5_phy_errata, 694c6fd2807SJeff Garzik .enable_leds = mv5_enable_leds, 695c6fd2807SJeff Garzik .read_preamp = mv5_read_preamp, 696c6fd2807SJeff Garzik .reset_hc = mv5_reset_hc, 697c6fd2807SJeff Garzik .reset_flash = mv5_reset_flash, 698c6fd2807SJeff Garzik .reset_bus = mv5_reset_bus, 699c6fd2807SJeff Garzik }; 700c6fd2807SJeff Garzik 701c6fd2807SJeff Garzik static const struct mv_hw_ops mv6xxx_ops = { 702c6fd2807SJeff Garzik .phy_errata = mv6_phy_errata, 703c6fd2807SJeff Garzik .enable_leds = mv6_enable_leds, 704c6fd2807SJeff Garzik .read_preamp = mv6_read_preamp, 705c6fd2807SJeff Garzik .reset_hc = mv6_reset_hc, 706c6fd2807SJeff Garzik .reset_flash = mv6_reset_flash, 707c6fd2807SJeff Garzik .reset_bus = mv_reset_pci_bus, 708c6fd2807SJeff Garzik }; 709c6fd2807SJeff Garzik 710f351b2d6SSaeed Bishara static const struct mv_hw_ops mv_soc_ops = { 711f351b2d6SSaeed Bishara .phy_errata = mv6_phy_errata, 712f351b2d6SSaeed Bishara .enable_leds = mv_soc_enable_leds, 713f351b2d6SSaeed Bishara .read_preamp = mv_soc_read_preamp, 714f351b2d6SSaeed Bishara .reset_hc = mv_soc_reset_hc, 715f351b2d6SSaeed Bishara .reset_flash = mv_soc_reset_flash, 716f351b2d6SSaeed Bishara .reset_bus = mv_soc_reset_bus, 717f351b2d6SSaeed Bishara }; 718f351b2d6SSaeed Bishara 719c6fd2807SJeff Garzik /* 720c6fd2807SJeff Garzik * Functions 721c6fd2807SJeff Garzik */ 722c6fd2807SJeff Garzik 723c6fd2807SJeff Garzik static inline void writelfl(unsigned long data, void __iomem *addr) 724c6fd2807SJeff Garzik { 725c6fd2807SJeff Garzik writel(data, addr); 726c6fd2807SJeff Garzik (void) readl(addr); /* flush to avoid PCI posted write */ 727c6fd2807SJeff Garzik } 728c6fd2807SJeff Garzik 729c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) 730c6fd2807SJeff Garzik { 731c6fd2807SJeff Garzik return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 732c6fd2807SJeff Garzik } 733c6fd2807SJeff Garzik 734c6fd2807SJeff Garzik static inline unsigned int mv_hc_from_port(unsigned int port) 735c6fd2807SJeff Garzik { 736c6fd2807SJeff Garzik return port >> MV_PORT_HC_SHIFT; 737c6fd2807SJeff Garzik } 738c6fd2807SJeff Garzik 739c6fd2807SJeff Garzik static inline unsigned int mv_hardport_from_port(unsigned int port) 740c6fd2807SJeff Garzik { 741c6fd2807SJeff Garzik return port & MV_PORT_MASK; 742c6fd2807SJeff Garzik } 743c6fd2807SJeff Garzik 744c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 745c6fd2807SJeff Garzik unsigned int port) 746c6fd2807SJeff Garzik { 747c6fd2807SJeff Garzik return mv_hc_base(base, mv_hc_from_port(port)); 748c6fd2807SJeff Garzik } 749c6fd2807SJeff Garzik 750c6fd2807SJeff Garzik static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) 751c6fd2807SJeff Garzik { 752c6fd2807SJeff Garzik return mv_hc_base_from_port(base, port) + 753c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ + 754c6fd2807SJeff Garzik (mv_hardport_from_port(port) * MV_PORT_REG_SZ); 755c6fd2807SJeff Garzik } 756c6fd2807SJeff Garzik 757f351b2d6SSaeed Bishara static inline void __iomem *mv_host_base(struct ata_host *host) 758f351b2d6SSaeed Bishara { 759f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 760f351b2d6SSaeed Bishara return hpriv->base; 761f351b2d6SSaeed Bishara } 762f351b2d6SSaeed Bishara 763c6fd2807SJeff Garzik static inline void __iomem *mv_ap_base(struct ata_port *ap) 764c6fd2807SJeff Garzik { 765f351b2d6SSaeed Bishara return mv_port_base(mv_host_base(ap->host), ap->port_no); 766c6fd2807SJeff Garzik } 767c6fd2807SJeff Garzik 768cca3974eSJeff Garzik static inline int mv_get_hc_count(unsigned long port_flags) 769c6fd2807SJeff Garzik { 770cca3974eSJeff Garzik return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 771c6fd2807SJeff Garzik } 772c6fd2807SJeff Garzik 773c5d3e45aSJeff Garzik static void mv_set_edma_ptrs(void __iomem *port_mmio, 774c5d3e45aSJeff Garzik struct mv_host_priv *hpriv, 775c5d3e45aSJeff Garzik struct mv_port_priv *pp) 776c5d3e45aSJeff Garzik { 777bdd4dddeSJeff Garzik u32 index; 778bdd4dddeSJeff Garzik 779c5d3e45aSJeff Garzik /* 780c5d3e45aSJeff Garzik * initialize request queue 781c5d3e45aSJeff Garzik */ 782bdd4dddeSJeff Garzik index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 783bdd4dddeSJeff Garzik 784c5d3e45aSJeff Garzik WARN_ON(pp->crqb_dma & 0x3ff); 785c5d3e45aSJeff Garzik writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 786bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index, 787c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 788c5d3e45aSJeff Garzik 789c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 790bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & 0xffffffff) | index, 791c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 792c5d3e45aSJeff Garzik else 793bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 794c5d3e45aSJeff Garzik 795c5d3e45aSJeff Garzik /* 796c5d3e45aSJeff Garzik * initialize response queue 797c5d3e45aSJeff Garzik */ 798bdd4dddeSJeff Garzik index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT; 799bdd4dddeSJeff Garzik 800c5d3e45aSJeff Garzik WARN_ON(pp->crpb_dma & 0xff); 801c5d3e45aSJeff Garzik writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 802c5d3e45aSJeff Garzik 803c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 804bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & 0xffffffff) | index, 805c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 806c5d3e45aSJeff Garzik else 807bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 808c5d3e45aSJeff Garzik 809bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index, 810c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 811c5d3e45aSJeff Garzik } 812c5d3e45aSJeff Garzik 813c6fd2807SJeff Garzik /** 814c6fd2807SJeff Garzik * mv_start_dma - Enable eDMA engine 815c6fd2807SJeff Garzik * @base: port base address 816c6fd2807SJeff Garzik * @pp: port private data 817c6fd2807SJeff Garzik * 818c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 819c6fd2807SJeff Garzik * WARN_ON. 820c6fd2807SJeff Garzik * 821c6fd2807SJeff Garzik * LOCKING: 822c6fd2807SJeff Garzik * Inherited from caller. 823c6fd2807SJeff Garzik */ 8240c58912eSMark Lord static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio, 82572109168SMark Lord struct mv_port_priv *pp, u8 protocol) 826c6fd2807SJeff Garzik { 82772109168SMark Lord int want_ncq = (protocol == ATA_PROT_NCQ); 82872109168SMark Lord 82972109168SMark Lord if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 83072109168SMark Lord int using_ncq = ((pp->pp_flags & MV_PP_FLAG_NCQ_EN) != 0); 83172109168SMark Lord if (want_ncq != using_ncq) 83272109168SMark Lord __mv_stop_dma(ap); 83372109168SMark Lord } 834c5d3e45aSJeff Garzik if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 8350c58912eSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 8360c58912eSMark Lord int hard_port = mv_hardport_from_port(ap->port_no); 8370c58912eSMark Lord void __iomem *hc_mmio = mv_hc_base_from_port( 8380fca0d6fSSaeed Bishara mv_host_base(ap->host), hard_port); 8390c58912eSMark Lord u32 hc_irq_cause, ipending; 8400c58912eSMark Lord 841bdd4dddeSJeff Garzik /* clear EDMA event indicators, if any */ 842f630d562SMark Lord writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 843bdd4dddeSJeff Garzik 8440c58912eSMark Lord /* clear EDMA interrupt indicator, if any */ 8450c58912eSMark Lord hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 8460c58912eSMark Lord ipending = (DEV_IRQ << hard_port) | 8470c58912eSMark Lord (CRPB_DMA_DONE << hard_port); 8480c58912eSMark Lord if (hc_irq_cause & ipending) { 8490c58912eSMark Lord writelfl(hc_irq_cause & ~ipending, 8500c58912eSMark Lord hc_mmio + HC_IRQ_CAUSE_OFS); 8510c58912eSMark Lord } 8520c58912eSMark Lord 85372109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, want_ncq); 8540c58912eSMark Lord 8550c58912eSMark Lord /* clear FIS IRQ Cause */ 8560c58912eSMark Lord writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS); 8570c58912eSMark Lord 858f630d562SMark Lord mv_set_edma_ptrs(port_mmio, hpriv, pp); 859bdd4dddeSJeff Garzik 860f630d562SMark Lord writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS); 861c6fd2807SJeff Garzik pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 862c6fd2807SJeff Garzik } 863f630d562SMark Lord WARN_ON(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); 864c6fd2807SJeff Garzik } 865c6fd2807SJeff Garzik 866c6fd2807SJeff Garzik /** 8670ea9e179SJeff Garzik * __mv_stop_dma - Disable eDMA engine 868c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 869c6fd2807SJeff Garzik * 870c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 871c6fd2807SJeff Garzik * WARN_ON. 872c6fd2807SJeff Garzik * 873c6fd2807SJeff Garzik * LOCKING: 874c6fd2807SJeff Garzik * Inherited from caller. 875c6fd2807SJeff Garzik */ 8760ea9e179SJeff Garzik static int __mv_stop_dma(struct ata_port *ap) 877c6fd2807SJeff Garzik { 878c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 879c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 880c6fd2807SJeff Garzik u32 reg; 881c5d3e45aSJeff Garzik int i, err = 0; 882c6fd2807SJeff Garzik 8834537deb5SJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 884c6fd2807SJeff Garzik /* Disable EDMA if active. The disable bit auto clears. 885c6fd2807SJeff Garzik */ 886c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 887c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 888c6fd2807SJeff Garzik } else { 889c6fd2807SJeff Garzik WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)); 890c6fd2807SJeff Garzik } 891c6fd2807SJeff Garzik 892c6fd2807SJeff Garzik /* now properly wait for the eDMA to stop */ 893c6fd2807SJeff Garzik for (i = 1000; i > 0; i--) { 894c6fd2807SJeff Garzik reg = readl(port_mmio + EDMA_CMD_OFS); 8954537deb5SJeff Garzik if (!(reg & EDMA_EN)) 896c6fd2807SJeff Garzik break; 8974537deb5SJeff Garzik 898c6fd2807SJeff Garzik udelay(100); 899c6fd2807SJeff Garzik } 900c6fd2807SJeff Garzik 901c5d3e45aSJeff Garzik if (reg & EDMA_EN) { 902c6fd2807SJeff Garzik ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 903c5d3e45aSJeff Garzik err = -EIO; 904c6fd2807SJeff Garzik } 905c5d3e45aSJeff Garzik 906c5d3e45aSJeff Garzik return err; 907c6fd2807SJeff Garzik } 908c6fd2807SJeff Garzik 9090ea9e179SJeff Garzik static int mv_stop_dma(struct ata_port *ap) 9100ea9e179SJeff Garzik { 9110ea9e179SJeff Garzik unsigned long flags; 9120ea9e179SJeff Garzik int rc; 9130ea9e179SJeff Garzik 9140ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 9150ea9e179SJeff Garzik rc = __mv_stop_dma(ap); 9160ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 9170ea9e179SJeff Garzik 9180ea9e179SJeff Garzik return rc; 9190ea9e179SJeff Garzik } 9200ea9e179SJeff Garzik 921c6fd2807SJeff Garzik #ifdef ATA_DEBUG 922c6fd2807SJeff Garzik static void mv_dump_mem(void __iomem *start, unsigned bytes) 923c6fd2807SJeff Garzik { 924c6fd2807SJeff Garzik int b, w; 925c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 926c6fd2807SJeff Garzik DPRINTK("%p: ", start + b); 927c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 928c6fd2807SJeff Garzik printk("%08x ", readl(start + b)); 929c6fd2807SJeff Garzik b += sizeof(u32); 930c6fd2807SJeff Garzik } 931c6fd2807SJeff Garzik printk("\n"); 932c6fd2807SJeff Garzik } 933c6fd2807SJeff Garzik } 934c6fd2807SJeff Garzik #endif 935c6fd2807SJeff Garzik 936c6fd2807SJeff Garzik static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes) 937c6fd2807SJeff Garzik { 938c6fd2807SJeff Garzik #ifdef ATA_DEBUG 939c6fd2807SJeff Garzik int b, w; 940c6fd2807SJeff Garzik u32 dw; 941c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 942c6fd2807SJeff Garzik DPRINTK("%02x: ", b); 943c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 944c6fd2807SJeff Garzik (void) pci_read_config_dword(pdev, b, &dw); 945c6fd2807SJeff Garzik printk("%08x ", dw); 946c6fd2807SJeff Garzik b += sizeof(u32); 947c6fd2807SJeff Garzik } 948c6fd2807SJeff Garzik printk("\n"); 949c6fd2807SJeff Garzik } 950c6fd2807SJeff Garzik #endif 951c6fd2807SJeff Garzik } 952c6fd2807SJeff Garzik static void mv_dump_all_regs(void __iomem *mmio_base, int port, 953c6fd2807SJeff Garzik struct pci_dev *pdev) 954c6fd2807SJeff Garzik { 955c6fd2807SJeff Garzik #ifdef ATA_DEBUG 956c6fd2807SJeff Garzik void __iomem *hc_base = mv_hc_base(mmio_base, 957c6fd2807SJeff Garzik port >> MV_PORT_HC_SHIFT); 958c6fd2807SJeff Garzik void __iomem *port_base; 959c6fd2807SJeff Garzik int start_port, num_ports, p, start_hc, num_hcs, hc; 960c6fd2807SJeff Garzik 961c6fd2807SJeff Garzik if (0 > port) { 962c6fd2807SJeff Garzik start_hc = start_port = 0; 963c6fd2807SJeff Garzik num_ports = 8; /* shld be benign for 4 port devs */ 964c6fd2807SJeff Garzik num_hcs = 2; 965c6fd2807SJeff Garzik } else { 966c6fd2807SJeff Garzik start_hc = port >> MV_PORT_HC_SHIFT; 967c6fd2807SJeff Garzik start_port = port; 968c6fd2807SJeff Garzik num_ports = num_hcs = 1; 969c6fd2807SJeff Garzik } 970c6fd2807SJeff Garzik DPRINTK("All registers for port(s) %u-%u:\n", start_port, 971c6fd2807SJeff Garzik num_ports > 1 ? num_ports - 1 : start_port); 972c6fd2807SJeff Garzik 973c6fd2807SJeff Garzik if (NULL != pdev) { 974c6fd2807SJeff Garzik DPRINTK("PCI config space regs:\n"); 975c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 976c6fd2807SJeff Garzik } 977c6fd2807SJeff Garzik DPRINTK("PCI regs:\n"); 978c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xc00, 0x3c); 979c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xd00, 0x34); 980c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xf00, 0x4); 981c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0x1d00, 0x6c); 982c6fd2807SJeff Garzik for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 983c6fd2807SJeff Garzik hc_base = mv_hc_base(mmio_base, hc); 984c6fd2807SJeff Garzik DPRINTK("HC regs (HC %i):\n", hc); 985c6fd2807SJeff Garzik mv_dump_mem(hc_base, 0x1c); 986c6fd2807SJeff Garzik } 987c6fd2807SJeff Garzik for (p = start_port; p < start_port + num_ports; p++) { 988c6fd2807SJeff Garzik port_base = mv_port_base(mmio_base, p); 989c6fd2807SJeff Garzik DPRINTK("EDMA regs (port %i):\n", p); 990c6fd2807SJeff Garzik mv_dump_mem(port_base, 0x54); 991c6fd2807SJeff Garzik DPRINTK("SATA regs (port %i):\n", p); 992c6fd2807SJeff Garzik mv_dump_mem(port_base+0x300, 0x60); 993c6fd2807SJeff Garzik } 994c6fd2807SJeff Garzik #endif 995c6fd2807SJeff Garzik } 996c6fd2807SJeff Garzik 997c6fd2807SJeff Garzik static unsigned int mv_scr_offset(unsigned int sc_reg_in) 998c6fd2807SJeff Garzik { 999c6fd2807SJeff Garzik unsigned int ofs; 1000c6fd2807SJeff Garzik 1001c6fd2807SJeff Garzik switch (sc_reg_in) { 1002c6fd2807SJeff Garzik case SCR_STATUS: 1003c6fd2807SJeff Garzik case SCR_CONTROL: 1004c6fd2807SJeff Garzik case SCR_ERROR: 1005c6fd2807SJeff Garzik ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32)); 1006c6fd2807SJeff Garzik break; 1007c6fd2807SJeff Garzik case SCR_ACTIVE: 1008c6fd2807SJeff Garzik ofs = SATA_ACTIVE_OFS; /* active is not with the others */ 1009c6fd2807SJeff Garzik break; 1010c6fd2807SJeff Garzik default: 1011c6fd2807SJeff Garzik ofs = 0xffffffffU; 1012c6fd2807SJeff Garzik break; 1013c6fd2807SJeff Garzik } 1014c6fd2807SJeff Garzik return ofs; 1015c6fd2807SJeff Garzik } 1016c6fd2807SJeff Garzik 1017da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1018c6fd2807SJeff Garzik { 1019c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1020c6fd2807SJeff Garzik 1021da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1022da3dbb17STejun Heo *val = readl(mv_ap_base(ap) + ofs); 1023da3dbb17STejun Heo return 0; 1024da3dbb17STejun Heo } else 1025da3dbb17STejun Heo return -EINVAL; 1026c6fd2807SJeff Garzik } 1027c6fd2807SJeff Garzik 1028da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1029c6fd2807SJeff Garzik { 1030c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1031c6fd2807SJeff Garzik 1032da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1033c6fd2807SJeff Garzik writelfl(val, mv_ap_base(ap) + ofs); 1034da3dbb17STejun Heo return 0; 1035da3dbb17STejun Heo } else 1036da3dbb17STejun Heo return -EINVAL; 1037c6fd2807SJeff Garzik } 1038c6fd2807SJeff Garzik 1039f273827eSMark Lord static void mv6_dev_config(struct ata_device *adev) 1040f273827eSMark Lord { 1041f273827eSMark Lord /* 1042f273827eSMark Lord * We don't have hob_nsect when doing NCQ commands on Gen-II. 1043f273827eSMark Lord * See mv_qc_prep() for more info. 1044f273827eSMark Lord */ 1045f273827eSMark Lord if (adev->flags & ATA_DFLAG_NCQ) 1046f273827eSMark Lord if (adev->max_sectors > ATA_MAX_SECTORS) 1047f273827eSMark Lord adev->max_sectors = ATA_MAX_SECTORS; 1048f273827eSMark Lord } 1049f273827eSMark Lord 105072109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 105172109168SMark Lord void __iomem *port_mmio, int want_ncq) 1052c6fd2807SJeff Garzik { 10530c58912eSMark Lord u32 cfg; 1054c6fd2807SJeff Garzik 1055c6fd2807SJeff Garzik /* set up non-NCQ EDMA configuration */ 10560c58912eSMark Lord cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */ 1057c6fd2807SJeff Garzik 10580c58912eSMark Lord if (IS_GEN_I(hpriv)) 1059c6fd2807SJeff Garzik cfg |= (1 << 8); /* enab config burst size mask */ 1060c6fd2807SJeff Garzik 10610c58912eSMark Lord else if (IS_GEN_II(hpriv)) 1062c6fd2807SJeff Garzik cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 1063c6fd2807SJeff Garzik 1064c6fd2807SJeff Garzik else if (IS_GEN_IIE(hpriv)) { 1065e728eabeSJeff Garzik cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */ 1066e728eabeSJeff Garzik cfg |= (1 << 22); /* enab 4-entry host queue cache */ 1067c6fd2807SJeff Garzik cfg |= (1 << 18); /* enab early completion */ 1068e728eabeSJeff Garzik cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ 1069c6fd2807SJeff Garzik } 1070c6fd2807SJeff Garzik 107172109168SMark Lord if (want_ncq) { 107272109168SMark Lord cfg |= EDMA_CFG_NCQ; 107372109168SMark Lord pp->pp_flags |= MV_PP_FLAG_NCQ_EN; 107472109168SMark Lord } else 107572109168SMark Lord pp->pp_flags &= ~MV_PP_FLAG_NCQ_EN; 107672109168SMark Lord 1077c6fd2807SJeff Garzik writelfl(cfg, port_mmio + EDMA_CFG_OFS); 1078c6fd2807SJeff Garzik } 1079c6fd2807SJeff Garzik 1080da2fa9baSMark Lord static void mv_port_free_dma_mem(struct ata_port *ap) 1081da2fa9baSMark Lord { 1082da2fa9baSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1083da2fa9baSMark Lord struct mv_port_priv *pp = ap->private_data; 1084eb73d558SMark Lord int tag; 1085da2fa9baSMark Lord 1086da2fa9baSMark Lord if (pp->crqb) { 1087da2fa9baSMark Lord dma_pool_free(hpriv->crqb_pool, pp->crqb, pp->crqb_dma); 1088da2fa9baSMark Lord pp->crqb = NULL; 1089da2fa9baSMark Lord } 1090da2fa9baSMark Lord if (pp->crpb) { 1091da2fa9baSMark Lord dma_pool_free(hpriv->crpb_pool, pp->crpb, pp->crpb_dma); 1092da2fa9baSMark Lord pp->crpb = NULL; 1093da2fa9baSMark Lord } 1094eb73d558SMark Lord /* 1095eb73d558SMark Lord * For GEN_I, there's no NCQ, so we have only a single sg_tbl. 1096eb73d558SMark Lord * For later hardware, we have one unique sg_tbl per NCQ tag. 1097eb73d558SMark Lord */ 1098eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1099eb73d558SMark Lord if (pp->sg_tbl[tag]) { 1100eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) 1101eb73d558SMark Lord dma_pool_free(hpriv->sg_tbl_pool, 1102eb73d558SMark Lord pp->sg_tbl[tag], 1103eb73d558SMark Lord pp->sg_tbl_dma[tag]); 1104eb73d558SMark Lord pp->sg_tbl[tag] = NULL; 1105eb73d558SMark Lord } 1106da2fa9baSMark Lord } 1107da2fa9baSMark Lord } 1108da2fa9baSMark Lord 1109c6fd2807SJeff Garzik /** 1110c6fd2807SJeff Garzik * mv_port_start - Port specific init/start routine. 1111c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1112c6fd2807SJeff Garzik * 1113c6fd2807SJeff Garzik * Allocate and point to DMA memory, init port private memory, 1114c6fd2807SJeff Garzik * zero indices. 1115c6fd2807SJeff Garzik * 1116c6fd2807SJeff Garzik * LOCKING: 1117c6fd2807SJeff Garzik * Inherited from caller. 1118c6fd2807SJeff Garzik */ 1119c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap) 1120c6fd2807SJeff Garzik { 1121cca3974eSJeff Garzik struct device *dev = ap->host->dev; 1122cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1123c6fd2807SJeff Garzik struct mv_port_priv *pp; 1124c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 11250ea9e179SJeff Garzik unsigned long flags; 1126dde20207SJames Bottomley int tag; 1127c6fd2807SJeff Garzik 112824dc5f33STejun Heo pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 1129c6fd2807SJeff Garzik if (!pp) 113024dc5f33STejun Heo return -ENOMEM; 1131da2fa9baSMark Lord ap->private_data = pp; 1132c6fd2807SJeff Garzik 1133da2fa9baSMark Lord pp->crqb = dma_pool_alloc(hpriv->crqb_pool, GFP_KERNEL, &pp->crqb_dma); 1134da2fa9baSMark Lord if (!pp->crqb) 1135da2fa9baSMark Lord return -ENOMEM; 1136da2fa9baSMark Lord memset(pp->crqb, 0, MV_CRQB_Q_SZ); 1137c6fd2807SJeff Garzik 1138da2fa9baSMark Lord pp->crpb = dma_pool_alloc(hpriv->crpb_pool, GFP_KERNEL, &pp->crpb_dma); 1139da2fa9baSMark Lord if (!pp->crpb) 1140da2fa9baSMark Lord goto out_port_free_dma_mem; 1141da2fa9baSMark Lord memset(pp->crpb, 0, MV_CRPB_Q_SZ); 1142c6fd2807SJeff Garzik 1143eb73d558SMark Lord /* 1144eb73d558SMark Lord * For GEN_I, there's no NCQ, so we only allocate a single sg_tbl. 1145eb73d558SMark Lord * For later hardware, we need one unique sg_tbl per NCQ tag. 1146eb73d558SMark Lord */ 1147eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1148eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) { 1149eb73d558SMark Lord pp->sg_tbl[tag] = dma_pool_alloc(hpriv->sg_tbl_pool, 1150eb73d558SMark Lord GFP_KERNEL, &pp->sg_tbl_dma[tag]); 1151eb73d558SMark Lord if (!pp->sg_tbl[tag]) 1152da2fa9baSMark Lord goto out_port_free_dma_mem; 1153eb73d558SMark Lord } else { 1154eb73d558SMark Lord pp->sg_tbl[tag] = pp->sg_tbl[0]; 1155eb73d558SMark Lord pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0]; 1156eb73d558SMark Lord } 1157eb73d558SMark Lord } 1158c6fd2807SJeff Garzik 11590ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 11600ea9e179SJeff Garzik 116172109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, 0); 1162c5d3e45aSJeff Garzik mv_set_edma_ptrs(port_mmio, hpriv, pp); 1163c6fd2807SJeff Garzik 11640ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 11650ea9e179SJeff Garzik 1166c6fd2807SJeff Garzik /* Don't turn on EDMA here...do it before DMA commands only. Else 1167c6fd2807SJeff Garzik * we'll be unable to send non-data, PIO, etc due to restricted access 1168c6fd2807SJeff Garzik * to shadow regs. 1169c6fd2807SJeff Garzik */ 1170c6fd2807SJeff Garzik return 0; 1171da2fa9baSMark Lord 1172da2fa9baSMark Lord out_port_free_dma_mem: 1173da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1174da2fa9baSMark Lord return -ENOMEM; 1175c6fd2807SJeff Garzik } 1176c6fd2807SJeff Garzik 1177c6fd2807SJeff Garzik /** 1178c6fd2807SJeff Garzik * mv_port_stop - Port specific cleanup/stop routine. 1179c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1180c6fd2807SJeff Garzik * 1181c6fd2807SJeff Garzik * Stop DMA, cleanup port memory. 1182c6fd2807SJeff Garzik * 1183c6fd2807SJeff Garzik * LOCKING: 1184cca3974eSJeff Garzik * This routine uses the host lock to protect the DMA stop. 1185c6fd2807SJeff Garzik */ 1186c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap) 1187c6fd2807SJeff Garzik { 1188c6fd2807SJeff Garzik mv_stop_dma(ap); 1189da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1190c6fd2807SJeff Garzik } 1191c6fd2807SJeff Garzik 1192c6fd2807SJeff Garzik /** 1193c6fd2807SJeff Garzik * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries 1194c6fd2807SJeff Garzik * @qc: queued command whose SG list to source from 1195c6fd2807SJeff Garzik * 1196c6fd2807SJeff Garzik * Populate the SG list and mark the last entry. 1197c6fd2807SJeff Garzik * 1198c6fd2807SJeff Garzik * LOCKING: 1199c6fd2807SJeff Garzik * Inherited from caller. 1200c6fd2807SJeff Garzik */ 12016c08772eSJeff Garzik static void mv_fill_sg(struct ata_queued_cmd *qc) 1202c6fd2807SJeff Garzik { 1203c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 1204c6fd2807SJeff Garzik struct scatterlist *sg; 12053be6cbd7SJeff Garzik struct mv_sg *mv_sg, *last_sg = NULL; 1206ff2aeb1eSTejun Heo unsigned int si; 1207c6fd2807SJeff Garzik 1208eb73d558SMark Lord mv_sg = pp->sg_tbl[qc->tag]; 1209ff2aeb1eSTejun Heo for_each_sg(qc->sg, sg, qc->n_elem, si) { 1210d88184fbSJeff Garzik dma_addr_t addr = sg_dma_address(sg); 1211d88184fbSJeff Garzik u32 sg_len = sg_dma_len(sg); 1212c6fd2807SJeff Garzik 12134007b493SOlof Johansson while (sg_len) { 12144007b493SOlof Johansson u32 offset = addr & 0xffff; 12154007b493SOlof Johansson u32 len = sg_len; 12164007b493SOlof Johansson 12174007b493SOlof Johansson if ((offset + sg_len > 0x10000)) 12184007b493SOlof Johansson len = 0x10000 - offset; 12194007b493SOlof Johansson 1220d88184fbSJeff Garzik mv_sg->addr = cpu_to_le32(addr & 0xffffffff); 1221d88184fbSJeff Garzik mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16); 12226c08772eSJeff Garzik mv_sg->flags_size = cpu_to_le32(len & 0xffff); 1223c6fd2807SJeff Garzik 12244007b493SOlof Johansson sg_len -= len; 12254007b493SOlof Johansson addr += len; 12264007b493SOlof Johansson 12273be6cbd7SJeff Garzik last_sg = mv_sg; 1228d88184fbSJeff Garzik mv_sg++; 1229c6fd2807SJeff Garzik } 12304007b493SOlof Johansson } 12313be6cbd7SJeff Garzik 12323be6cbd7SJeff Garzik if (likely(last_sg)) 12333be6cbd7SJeff Garzik last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 1234c6fd2807SJeff Garzik } 1235c6fd2807SJeff Garzik 12365796d1c4SJeff Garzik static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1237c6fd2807SJeff Garzik { 1238c6fd2807SJeff Garzik u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 1239c6fd2807SJeff Garzik (last ? CRQB_CMD_LAST : 0); 1240c6fd2807SJeff Garzik *cmdw = cpu_to_le16(tmp); 1241c6fd2807SJeff Garzik } 1242c6fd2807SJeff Garzik 1243c6fd2807SJeff Garzik /** 1244c6fd2807SJeff Garzik * mv_qc_prep - Host specific command preparation. 1245c6fd2807SJeff Garzik * @qc: queued command to prepare 1246c6fd2807SJeff Garzik * 1247c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1248c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1249c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1250c6fd2807SJeff Garzik * the SG load routine. 1251c6fd2807SJeff Garzik * 1252c6fd2807SJeff Garzik * LOCKING: 1253c6fd2807SJeff Garzik * Inherited from caller. 1254c6fd2807SJeff Garzik */ 1255c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc) 1256c6fd2807SJeff Garzik { 1257c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1258c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1259c6fd2807SJeff Garzik __le16 *cw; 1260c6fd2807SJeff Garzik struct ata_taskfile *tf; 1261c6fd2807SJeff Garzik u16 flags = 0; 1262c6fd2807SJeff Garzik unsigned in_index; 1263c6fd2807SJeff Garzik 1264138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1265138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1266c6fd2807SJeff Garzik return; 1267c6fd2807SJeff Garzik 1268c6fd2807SJeff Garzik /* Fill in command request block 1269c6fd2807SJeff Garzik */ 1270c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1271c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1272c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1273c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 1274c6fd2807SJeff Garzik 1275bdd4dddeSJeff Garzik /* get current queue index from software */ 1276bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1277c6fd2807SJeff Garzik 1278c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr = 1279eb73d558SMark Lord cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1280c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr_hi = 1281eb73d558SMark Lord cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1282c6fd2807SJeff Garzik pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags); 1283c6fd2807SJeff Garzik 1284c6fd2807SJeff Garzik cw = &pp->crqb[in_index].ata_cmd[0]; 1285c6fd2807SJeff Garzik tf = &qc->tf; 1286c6fd2807SJeff Garzik 1287c6fd2807SJeff Garzik /* Sadly, the CRQB cannot accomodate all registers--there are 1288c6fd2807SJeff Garzik * only 11 bytes...so we must pick and choose required 1289c6fd2807SJeff Garzik * registers based on the command. So, we drop feature and 1290c6fd2807SJeff Garzik * hob_feature for [RW] DMA commands, but they are needed for 1291c6fd2807SJeff Garzik * NCQ. NCQ will drop hob_nsect. 1292c6fd2807SJeff Garzik */ 1293c6fd2807SJeff Garzik switch (tf->command) { 1294c6fd2807SJeff Garzik case ATA_CMD_READ: 1295c6fd2807SJeff Garzik case ATA_CMD_READ_EXT: 1296c6fd2807SJeff Garzik case ATA_CMD_WRITE: 1297c6fd2807SJeff Garzik case ATA_CMD_WRITE_EXT: 1298c6fd2807SJeff Garzik case ATA_CMD_WRITE_FUA_EXT: 1299c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0); 1300c6fd2807SJeff Garzik break; 1301c6fd2807SJeff Garzik case ATA_CMD_FPDMA_READ: 1302c6fd2807SJeff Garzik case ATA_CMD_FPDMA_WRITE: 1303c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); 1304c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); 1305c6fd2807SJeff Garzik break; 1306c6fd2807SJeff Garzik default: 1307c6fd2807SJeff Garzik /* The only other commands EDMA supports in non-queued and 1308c6fd2807SJeff Garzik * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none 1309c6fd2807SJeff Garzik * of which are defined/used by Linux. If we get here, this 1310c6fd2807SJeff Garzik * driver needs work. 1311c6fd2807SJeff Garzik * 1312c6fd2807SJeff Garzik * FIXME: modify libata to give qc_prep a return value and 1313c6fd2807SJeff Garzik * return error here. 1314c6fd2807SJeff Garzik */ 1315c6fd2807SJeff Garzik BUG_ON(tf->command); 1316c6fd2807SJeff Garzik break; 1317c6fd2807SJeff Garzik } 1318c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0); 1319c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0); 1320c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0); 1321c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0); 1322c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0); 1323c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0); 1324c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0); 1325c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 1326c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 1327c6fd2807SJeff Garzik 1328c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1329c6fd2807SJeff Garzik return; 1330c6fd2807SJeff Garzik mv_fill_sg(qc); 1331c6fd2807SJeff Garzik } 1332c6fd2807SJeff Garzik 1333c6fd2807SJeff Garzik /** 1334c6fd2807SJeff Garzik * mv_qc_prep_iie - Host specific command preparation. 1335c6fd2807SJeff Garzik * @qc: queued command to prepare 1336c6fd2807SJeff Garzik * 1337c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1338c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1339c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1340c6fd2807SJeff Garzik * the SG load routine. 1341c6fd2807SJeff Garzik * 1342c6fd2807SJeff Garzik * LOCKING: 1343c6fd2807SJeff Garzik * Inherited from caller. 1344c6fd2807SJeff Garzik */ 1345c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc) 1346c6fd2807SJeff Garzik { 1347c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1348c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1349c6fd2807SJeff Garzik struct mv_crqb_iie *crqb; 1350c6fd2807SJeff Garzik struct ata_taskfile *tf; 1351c6fd2807SJeff Garzik unsigned in_index; 1352c6fd2807SJeff Garzik u32 flags = 0; 1353c6fd2807SJeff Garzik 1354138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1355138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1356c6fd2807SJeff Garzik return; 1357c6fd2807SJeff Garzik 1358c6fd2807SJeff Garzik /* Fill in Gen IIE command request block 1359c6fd2807SJeff Garzik */ 1360c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1361c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1362c6fd2807SJeff Garzik 1363c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1364c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 13658c0aeb4aSMark Lord flags |= qc->tag << CRQB_HOSTQ_SHIFT; 1366c6fd2807SJeff Garzik 1367bdd4dddeSJeff Garzik /* get current queue index from software */ 1368bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1369c6fd2807SJeff Garzik 1370c6fd2807SJeff Garzik crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1371eb73d558SMark Lord crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1372eb73d558SMark Lord crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1373c6fd2807SJeff Garzik crqb->flags = cpu_to_le32(flags); 1374c6fd2807SJeff Garzik 1375c6fd2807SJeff Garzik tf = &qc->tf; 1376c6fd2807SJeff Garzik crqb->ata_cmd[0] = cpu_to_le32( 1377c6fd2807SJeff Garzik (tf->command << 16) | 1378c6fd2807SJeff Garzik (tf->feature << 24) 1379c6fd2807SJeff Garzik ); 1380c6fd2807SJeff Garzik crqb->ata_cmd[1] = cpu_to_le32( 1381c6fd2807SJeff Garzik (tf->lbal << 0) | 1382c6fd2807SJeff Garzik (tf->lbam << 8) | 1383c6fd2807SJeff Garzik (tf->lbah << 16) | 1384c6fd2807SJeff Garzik (tf->device << 24) 1385c6fd2807SJeff Garzik ); 1386c6fd2807SJeff Garzik crqb->ata_cmd[2] = cpu_to_le32( 1387c6fd2807SJeff Garzik (tf->hob_lbal << 0) | 1388c6fd2807SJeff Garzik (tf->hob_lbam << 8) | 1389c6fd2807SJeff Garzik (tf->hob_lbah << 16) | 1390c6fd2807SJeff Garzik (tf->hob_feature << 24) 1391c6fd2807SJeff Garzik ); 1392c6fd2807SJeff Garzik crqb->ata_cmd[3] = cpu_to_le32( 1393c6fd2807SJeff Garzik (tf->nsect << 0) | 1394c6fd2807SJeff Garzik (tf->hob_nsect << 8) 1395c6fd2807SJeff Garzik ); 1396c6fd2807SJeff Garzik 1397c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1398c6fd2807SJeff Garzik return; 1399c6fd2807SJeff Garzik mv_fill_sg(qc); 1400c6fd2807SJeff Garzik } 1401c6fd2807SJeff Garzik 1402c6fd2807SJeff Garzik /** 1403c6fd2807SJeff Garzik * mv_qc_issue - Initiate a command to the host 1404c6fd2807SJeff Garzik * @qc: queued command to start 1405c6fd2807SJeff Garzik * 1406c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1407c6fd2807SJeff Garzik * if command is not DMA. Else, it sanity checks our local 1408c6fd2807SJeff Garzik * caches of the request producer/consumer indices then enables 1409c6fd2807SJeff Garzik * DMA and bumps the request producer index. 1410c6fd2807SJeff Garzik * 1411c6fd2807SJeff Garzik * LOCKING: 1412c6fd2807SJeff Garzik * Inherited from caller. 1413c6fd2807SJeff Garzik */ 1414c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 1415c6fd2807SJeff Garzik { 1416c5d3e45aSJeff Garzik struct ata_port *ap = qc->ap; 1417c5d3e45aSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1418c5d3e45aSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1419bdd4dddeSJeff Garzik u32 in_index; 1420c6fd2807SJeff Garzik 1421138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1422138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) { 1423c6fd2807SJeff Garzik /* We're about to send a non-EDMA capable command to the 1424c6fd2807SJeff Garzik * port. Turn off EDMA so there won't be problems accessing 1425c6fd2807SJeff Garzik * shadow block, etc registers. 1426c6fd2807SJeff Garzik */ 14270ea9e179SJeff Garzik __mv_stop_dma(ap); 1428c6fd2807SJeff Garzik return ata_qc_issue_prot(qc); 1429c6fd2807SJeff Garzik } 1430c6fd2807SJeff Garzik 143172109168SMark Lord mv_start_dma(ap, port_mmio, pp, qc->tf.protocol); 1432bdd4dddeSJeff Garzik 1433bdd4dddeSJeff Garzik pp->req_idx++; 1434c6fd2807SJeff Garzik 1435bdd4dddeSJeff Garzik in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 1436c6fd2807SJeff Garzik 1437c6fd2807SJeff Garzik /* and write the request in pointer to kick the EDMA to life */ 1438bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 1439bdd4dddeSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1440c6fd2807SJeff Garzik 1441c6fd2807SJeff Garzik return 0; 1442c6fd2807SJeff Garzik } 1443c6fd2807SJeff Garzik 1444c6fd2807SJeff Garzik /** 1445c6fd2807SJeff Garzik * mv_err_intr - Handle error interrupts on the port 1446c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1447c6fd2807SJeff Garzik * @reset_allowed: bool: 0 == don't trigger from reset here 1448c6fd2807SJeff Garzik * 1449c6fd2807SJeff Garzik * In most cases, just clear the interrupt and move on. However, 1450c6fd2807SJeff Garzik * some cases require an eDMA reset, which is done right before 1451c6fd2807SJeff Garzik * the COMRESET in mv_phy_reset(). The SERR case requires a 1452c6fd2807SJeff Garzik * clear of pending errors in the SATA SERROR register. Finally, 1453c6fd2807SJeff Garzik * if the port disabled DMA, update our cached copy to match. 1454c6fd2807SJeff Garzik * 1455c6fd2807SJeff Garzik * LOCKING: 1456c6fd2807SJeff Garzik * Inherited from caller. 1457c6fd2807SJeff Garzik */ 1458bdd4dddeSJeff Garzik static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 1459c6fd2807SJeff Garzik { 1460c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1461bdd4dddeSJeff Garzik u32 edma_err_cause, eh_freeze_mask, serr = 0; 1462bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1463bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1464bdd4dddeSJeff Garzik unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN); 1465bdd4dddeSJeff Garzik unsigned int action = 0, err_mask = 0; 14669af5c9c9STejun Heo struct ata_eh_info *ehi = &ap->link.eh_info; 1467c6fd2807SJeff Garzik 1468bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1469c6fd2807SJeff Garzik 1470bdd4dddeSJeff Garzik if (!edma_enabled) { 1471bdd4dddeSJeff Garzik /* just a guess: do we need to do this? should we 1472bdd4dddeSJeff Garzik * expand this, and do it in all cases? 1473bdd4dddeSJeff Garzik */ 1474936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1475936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1476c6fd2807SJeff Garzik } 1477bdd4dddeSJeff Garzik 1478bdd4dddeSJeff Garzik edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1479bdd4dddeSJeff Garzik 1480bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause); 1481bdd4dddeSJeff Garzik 1482bdd4dddeSJeff Garzik /* 1483bdd4dddeSJeff Garzik * all generations share these EDMA error cause bits 1484bdd4dddeSJeff Garzik */ 1485bdd4dddeSJeff Garzik 1486bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_DEV) 1487bdd4dddeSJeff Garzik err_mask |= AC_ERR_DEV; 1488bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 14896c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR | 1490bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR)) { 1491bdd4dddeSJeff Garzik err_mask |= AC_ERR_ATA_BUS; 1492cf480626STejun Heo action |= ATA_EH_RESET; 1493b64bbc39STejun Heo ata_ehi_push_desc(ehi, "parity error"); 1494bdd4dddeSJeff Garzik } 1495bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { 1496bdd4dddeSJeff Garzik ata_ehi_hotplugged(ehi); 1497bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? 1498b64bbc39STejun Heo "dev disconnect" : "dev connect"); 1499cf480626STejun Heo action |= ATA_EH_RESET; 1500bdd4dddeSJeff Garzik } 1501bdd4dddeSJeff Garzik 1502ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) { 1503bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE_5; 1504bdd4dddeSJeff Garzik 1505bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 15065ab063e3SHarvey Harrison pp = ap->private_data; 1507c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1508b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1509c6fd2807SJeff Garzik } 1510bdd4dddeSJeff Garzik } else { 1511bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE; 1512bdd4dddeSJeff Garzik 1513bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS) { 15145ab063e3SHarvey Harrison pp = ap->private_data; 1515bdd4dddeSJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1516b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1517bdd4dddeSJeff Garzik } 1518bdd4dddeSJeff Garzik 1519bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SERR) { 1520936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1521936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1522bdd4dddeSJeff Garzik err_mask = AC_ERR_ATA_BUS; 1523cf480626STejun Heo action |= ATA_EH_RESET; 1524bdd4dddeSJeff Garzik } 1525bdd4dddeSJeff Garzik } 1526c6fd2807SJeff Garzik 1527c6fd2807SJeff Garzik /* Clear EDMA now that SERR cleanup done */ 15283606a380SMark Lord writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1529c6fd2807SJeff Garzik 1530bdd4dddeSJeff Garzik if (!err_mask) { 1531bdd4dddeSJeff Garzik err_mask = AC_ERR_OTHER; 1532cf480626STejun Heo action |= ATA_EH_RESET; 1533bdd4dddeSJeff Garzik } 1534bdd4dddeSJeff Garzik 1535bdd4dddeSJeff Garzik ehi->serror |= serr; 1536bdd4dddeSJeff Garzik ehi->action |= action; 1537bdd4dddeSJeff Garzik 1538bdd4dddeSJeff Garzik if (qc) 1539bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1540bdd4dddeSJeff Garzik else 1541bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1542bdd4dddeSJeff Garzik 1543bdd4dddeSJeff Garzik if (edma_err_cause & eh_freeze_mask) 1544bdd4dddeSJeff Garzik ata_port_freeze(ap); 1545bdd4dddeSJeff Garzik else 1546bdd4dddeSJeff Garzik ata_port_abort(ap); 1547bdd4dddeSJeff Garzik } 1548bdd4dddeSJeff Garzik 1549bdd4dddeSJeff Garzik static void mv_intr_pio(struct ata_port *ap) 1550bdd4dddeSJeff Garzik { 1551bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1552bdd4dddeSJeff Garzik u8 ata_status; 1553bdd4dddeSJeff Garzik 1554bdd4dddeSJeff Garzik /* ignore spurious intr if drive still BUSY */ 1555bdd4dddeSJeff Garzik ata_status = readb(ap->ioaddr.status_addr); 1556bdd4dddeSJeff Garzik if (unlikely(ata_status & ATA_BUSY)) 1557bdd4dddeSJeff Garzik return; 1558bdd4dddeSJeff Garzik 1559bdd4dddeSJeff Garzik /* get active ATA command */ 15609af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1561bdd4dddeSJeff Garzik if (unlikely(!qc)) /* no active tag */ 1562bdd4dddeSJeff Garzik return; 1563bdd4dddeSJeff Garzik if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */ 1564bdd4dddeSJeff Garzik return; 1565bdd4dddeSJeff Garzik 1566bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1567bdd4dddeSJeff Garzik qc->err_mask |= ac_err_mask(ata_status); 1568bdd4dddeSJeff Garzik ata_qc_complete(qc); 1569bdd4dddeSJeff Garzik } 1570bdd4dddeSJeff Garzik 1571bdd4dddeSJeff Garzik static void mv_intr_edma(struct ata_port *ap) 1572bdd4dddeSJeff Garzik { 1573bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1574bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1575bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1576bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1577bdd4dddeSJeff Garzik u32 out_index, in_index; 1578bdd4dddeSJeff Garzik bool work_done = false; 1579bdd4dddeSJeff Garzik 1580bdd4dddeSJeff Garzik /* get h/w response queue pointer */ 1581bdd4dddeSJeff Garzik in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) 1582bdd4dddeSJeff Garzik >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1583bdd4dddeSJeff Garzik 1584bdd4dddeSJeff Garzik while (1) { 1585bdd4dddeSJeff Garzik u16 status; 15866c1153e0SJeff Garzik unsigned int tag; 1587bdd4dddeSJeff Garzik 1588bdd4dddeSJeff Garzik /* get s/w response queue last-read pointer, and compare */ 1589bdd4dddeSJeff Garzik out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; 1590bdd4dddeSJeff Garzik if (in_index == out_index) 1591bdd4dddeSJeff Garzik break; 1592bdd4dddeSJeff Garzik 1593bdd4dddeSJeff Garzik /* 50xx: get active ATA command */ 1594bdd4dddeSJeff Garzik if (IS_GEN_I(hpriv)) 15959af5c9c9STejun Heo tag = ap->link.active_tag; 1596bdd4dddeSJeff Garzik 15976c1153e0SJeff Garzik /* Gen II/IIE: get active ATA command via tag, to enable 15986c1153e0SJeff Garzik * support for queueing. this works transparently for 15996c1153e0SJeff Garzik * queued and non-queued modes. 1600bdd4dddeSJeff Garzik */ 16018c0aeb4aSMark Lord else 16028c0aeb4aSMark Lord tag = le16_to_cpu(pp->crpb[out_index].id) & 0x1f; 1603bdd4dddeSJeff Garzik 1604bdd4dddeSJeff Garzik qc = ata_qc_from_tag(ap, tag); 1605bdd4dddeSJeff Garzik 1606cb924419SMark Lord /* For non-NCQ mode, the lower 8 bits of status 1607cb924419SMark Lord * are from EDMA_ERR_IRQ_CAUSE_OFS, 1608cb924419SMark Lord * which should be zero if all went well. 1609bdd4dddeSJeff Garzik */ 1610bdd4dddeSJeff Garzik status = le16_to_cpu(pp->crpb[out_index].flags); 1611cb924419SMark Lord if ((status & 0xff) && !(pp->pp_flags & MV_PP_FLAG_NCQ_EN)) { 1612bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1613bdd4dddeSJeff Garzik return; 1614bdd4dddeSJeff Garzik } 1615bdd4dddeSJeff Garzik 1616bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1617bdd4dddeSJeff Garzik if (qc) { 1618bdd4dddeSJeff Garzik qc->err_mask |= 1619bdd4dddeSJeff Garzik ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT); 1620bdd4dddeSJeff Garzik ata_qc_complete(qc); 1621bdd4dddeSJeff Garzik } 1622bdd4dddeSJeff Garzik 1623bdd4dddeSJeff Garzik /* advance software response queue pointer, to 1624bdd4dddeSJeff Garzik * indicate (after the loop completes) to hardware 1625bdd4dddeSJeff Garzik * that we have consumed a response queue entry. 1626bdd4dddeSJeff Garzik */ 1627bdd4dddeSJeff Garzik work_done = true; 1628bdd4dddeSJeff Garzik pp->resp_idx++; 1629bdd4dddeSJeff Garzik } 1630bdd4dddeSJeff Garzik 1631bdd4dddeSJeff Garzik if (work_done) 1632bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 1633bdd4dddeSJeff Garzik (out_index << EDMA_RSP_Q_PTR_SHIFT), 1634bdd4dddeSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1635c6fd2807SJeff Garzik } 1636c6fd2807SJeff Garzik 1637c6fd2807SJeff Garzik /** 1638c6fd2807SJeff Garzik * mv_host_intr - Handle all interrupts on the given host controller 1639cca3974eSJeff Garzik * @host: host specific structure 1640c6fd2807SJeff Garzik * @relevant: port error bits relevant to this host controller 1641c6fd2807SJeff Garzik * @hc: which host controller we're to look at 1642c6fd2807SJeff Garzik * 1643c6fd2807SJeff Garzik * Read then write clear the HC interrupt status then walk each 1644c6fd2807SJeff Garzik * port connected to the HC and see if it needs servicing. Port 1645c6fd2807SJeff Garzik * success ints are reported in the HC interrupt status reg, the 1646c6fd2807SJeff Garzik * port error ints are reported in the higher level main 1647c6fd2807SJeff Garzik * interrupt status register and thus are passed in via the 1648c6fd2807SJeff Garzik * 'relevant' argument. 1649c6fd2807SJeff Garzik * 1650c6fd2807SJeff Garzik * LOCKING: 1651c6fd2807SJeff Garzik * Inherited from caller. 1652c6fd2807SJeff Garzik */ 1653cca3974eSJeff Garzik static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1654c6fd2807SJeff Garzik { 1655f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 1656f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 1657c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1658c6fd2807SJeff Garzik u32 hc_irq_cause; 1659f351b2d6SSaeed Bishara int port, port0, last_port; 1660c6fd2807SJeff Garzik 166135177265SJeff Garzik if (hc == 0) 1662c6fd2807SJeff Garzik port0 = 0; 166335177265SJeff Garzik else 1664c6fd2807SJeff Garzik port0 = MV_PORTS_PER_HC; 1665c6fd2807SJeff Garzik 1666f351b2d6SSaeed Bishara if (HAS_PCI(host)) 1667f351b2d6SSaeed Bishara last_port = port0 + MV_PORTS_PER_HC; 1668f351b2d6SSaeed Bishara else 1669f351b2d6SSaeed Bishara last_port = port0 + hpriv->n_ports; 1670c6fd2807SJeff Garzik /* we'll need the HC success int register in most cases */ 1671c6fd2807SJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1672bdd4dddeSJeff Garzik if (!hc_irq_cause) 1673bdd4dddeSJeff Garzik return; 1674bdd4dddeSJeff Garzik 1675c6fd2807SJeff Garzik writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1676c6fd2807SJeff Garzik 1677c6fd2807SJeff Garzik VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1678c6fd2807SJeff Garzik hc, relevant, hc_irq_cause); 1679c6fd2807SJeff Garzik 16808f71efe2SYinghai Lu for (port = port0; port < last_port; port++) { 1681cca3974eSJeff Garzik struct ata_port *ap = host->ports[port]; 16828f71efe2SYinghai Lu struct mv_port_priv *pp; 1683bdd4dddeSJeff Garzik int have_err_bits, hard_port, shift; 1684c6fd2807SJeff Garzik 1685bdd4dddeSJeff Garzik if ((!ap) || (ap->flags & ATA_FLAG_DISABLED)) 1686c6fd2807SJeff Garzik continue; 1687c6fd2807SJeff Garzik 16888f71efe2SYinghai Lu pp = ap->private_data; 16898f71efe2SYinghai Lu 1690c6fd2807SJeff Garzik shift = port << 1; /* (port * 2) */ 1691c6fd2807SJeff Garzik if (port >= MV_PORTS_PER_HC) { 1692c6fd2807SJeff Garzik shift++; /* skip bit 8 in the HC Main IRQ reg */ 1693c6fd2807SJeff Garzik } 1694bdd4dddeSJeff Garzik have_err_bits = ((PORT0_ERR << shift) & relevant); 1695bdd4dddeSJeff Garzik 1696bdd4dddeSJeff Garzik if (unlikely(have_err_bits)) { 1697bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1698bdd4dddeSJeff Garzik 16999af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1700bdd4dddeSJeff Garzik if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) 1701bdd4dddeSJeff Garzik continue; 1702bdd4dddeSJeff Garzik 1703bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1704bdd4dddeSJeff Garzik continue; 1705c6fd2807SJeff Garzik } 1706c6fd2807SJeff Garzik 1707bdd4dddeSJeff Garzik hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1708bdd4dddeSJeff Garzik 1709bdd4dddeSJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1710bdd4dddeSJeff Garzik if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) 1711bdd4dddeSJeff Garzik mv_intr_edma(ap); 1712bdd4dddeSJeff Garzik } else { 1713bdd4dddeSJeff Garzik if ((DEV_IRQ << hard_port) & hc_irq_cause) 1714bdd4dddeSJeff Garzik mv_intr_pio(ap); 1715c6fd2807SJeff Garzik } 1716c6fd2807SJeff Garzik } 1717c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 1718c6fd2807SJeff Garzik } 1719c6fd2807SJeff Garzik 1720bdd4dddeSJeff Garzik static void mv_pci_error(struct ata_host *host, void __iomem *mmio) 1721bdd4dddeSJeff Garzik { 172202a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 1723bdd4dddeSJeff Garzik struct ata_port *ap; 1724bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1725bdd4dddeSJeff Garzik struct ata_eh_info *ehi; 1726bdd4dddeSJeff Garzik unsigned int i, err_mask, printed = 0; 1727bdd4dddeSJeff Garzik u32 err_cause; 1728bdd4dddeSJeff Garzik 172902a121daSMark Lord err_cause = readl(mmio + hpriv->irq_cause_ofs); 1730bdd4dddeSJeff Garzik 1731bdd4dddeSJeff Garzik dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", 1732bdd4dddeSJeff Garzik err_cause); 1733bdd4dddeSJeff Garzik 1734bdd4dddeSJeff Garzik DPRINTK("All regs @ PCI error\n"); 1735bdd4dddeSJeff Garzik mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 1736bdd4dddeSJeff Garzik 173702a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 1738bdd4dddeSJeff Garzik 1739bdd4dddeSJeff Garzik for (i = 0; i < host->n_ports; i++) { 1740bdd4dddeSJeff Garzik ap = host->ports[i]; 1741936fd732STejun Heo if (!ata_link_offline(&ap->link)) { 17429af5c9c9STejun Heo ehi = &ap->link.eh_info; 1743bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1744bdd4dddeSJeff Garzik if (!printed++) 1745bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, 1746bdd4dddeSJeff Garzik "PCI err cause 0x%08x", err_cause); 1747bdd4dddeSJeff Garzik err_mask = AC_ERR_HOST_BUS; 1748cf480626STejun Heo ehi->action = ATA_EH_RESET; 17499af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1750bdd4dddeSJeff Garzik if (qc) 1751bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1752bdd4dddeSJeff Garzik else 1753bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1754bdd4dddeSJeff Garzik 1755bdd4dddeSJeff Garzik ata_port_freeze(ap); 1756bdd4dddeSJeff Garzik } 1757bdd4dddeSJeff Garzik } 1758bdd4dddeSJeff Garzik } 1759bdd4dddeSJeff Garzik 1760c6fd2807SJeff Garzik /** 1761c5d3e45aSJeff Garzik * mv_interrupt - Main interrupt event handler 1762c6fd2807SJeff Garzik * @irq: unused 1763c6fd2807SJeff Garzik * @dev_instance: private data; in this case the host structure 1764c6fd2807SJeff Garzik * 1765c6fd2807SJeff Garzik * Read the read only register to determine if any host 1766c6fd2807SJeff Garzik * controllers have pending interrupts. If so, call lower level 1767c6fd2807SJeff Garzik * routine to handle. Also check for PCI errors which are only 1768c6fd2807SJeff Garzik * reported here. 1769c6fd2807SJeff Garzik * 1770c6fd2807SJeff Garzik * LOCKING: 1771cca3974eSJeff Garzik * This routine holds the host lock while processing pending 1772c6fd2807SJeff Garzik * interrupts. 1773c6fd2807SJeff Garzik */ 17747d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance) 1775c6fd2807SJeff Garzik { 1776cca3974eSJeff Garzik struct ata_host *host = dev_instance; 1777f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = host->private_data; 1778c6fd2807SJeff Garzik unsigned int hc, handled = 0, n_hcs; 1779f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 1780646a4da5SMark Lord u32 irq_stat, irq_mask; 1781c6fd2807SJeff Garzik 1782646a4da5SMark Lord spin_lock(&host->lock); 1783f351b2d6SSaeed Bishara 1784f351b2d6SSaeed Bishara irq_stat = readl(hpriv->main_cause_reg_addr); 1785f351b2d6SSaeed Bishara irq_mask = readl(hpriv->main_mask_reg_addr); 1786c6fd2807SJeff Garzik 1787c6fd2807SJeff Garzik /* check the cases where we either have nothing pending or have read 1788c6fd2807SJeff Garzik * a bogus register value which can indicate HW removal or PCI fault 1789c6fd2807SJeff Garzik */ 1790646a4da5SMark Lord if (!(irq_stat & irq_mask) || (0xffffffffU == irq_stat)) 1791646a4da5SMark Lord goto out_unlock; 1792c6fd2807SJeff Garzik 1793cca3974eSJeff Garzik n_hcs = mv_get_hc_count(host->ports[0]->flags); 1794c6fd2807SJeff Garzik 17957bb3c529SSaeed Bishara if (unlikely((irq_stat & PCI_ERR) && HAS_PCI(host))) { 1796bdd4dddeSJeff Garzik mv_pci_error(host, mmio); 1797bdd4dddeSJeff Garzik handled = 1; 1798bdd4dddeSJeff Garzik goto out_unlock; /* skip all other HC irq handling */ 1799bdd4dddeSJeff Garzik } 1800bdd4dddeSJeff Garzik 1801c6fd2807SJeff Garzik for (hc = 0; hc < n_hcs; hc++) { 1802c6fd2807SJeff Garzik u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1803c6fd2807SJeff Garzik if (relevant) { 1804cca3974eSJeff Garzik mv_host_intr(host, relevant, hc); 1805bdd4dddeSJeff Garzik handled = 1; 1806c6fd2807SJeff Garzik } 1807c6fd2807SJeff Garzik } 1808c6fd2807SJeff Garzik 1809bdd4dddeSJeff Garzik out_unlock: 1810cca3974eSJeff Garzik spin_unlock(&host->lock); 1811c6fd2807SJeff Garzik 1812c6fd2807SJeff Garzik return IRQ_RETVAL(handled); 1813c6fd2807SJeff Garzik } 1814c6fd2807SJeff Garzik 1815c6fd2807SJeff Garzik static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) 1816c6fd2807SJeff Garzik { 1817c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); 1818c6fd2807SJeff Garzik unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; 1819c6fd2807SJeff Garzik 1820c6fd2807SJeff Garzik return hc_mmio + ofs; 1821c6fd2807SJeff Garzik } 1822c6fd2807SJeff Garzik 1823c6fd2807SJeff Garzik static unsigned int mv5_scr_offset(unsigned int sc_reg_in) 1824c6fd2807SJeff Garzik { 1825c6fd2807SJeff Garzik unsigned int ofs; 1826c6fd2807SJeff Garzik 1827c6fd2807SJeff Garzik switch (sc_reg_in) { 1828c6fd2807SJeff Garzik case SCR_STATUS: 1829c6fd2807SJeff Garzik case SCR_ERROR: 1830c6fd2807SJeff Garzik case SCR_CONTROL: 1831c6fd2807SJeff Garzik ofs = sc_reg_in * sizeof(u32); 1832c6fd2807SJeff Garzik break; 1833c6fd2807SJeff Garzik default: 1834c6fd2807SJeff Garzik ofs = 0xffffffffU; 1835c6fd2807SJeff Garzik break; 1836c6fd2807SJeff Garzik } 1837c6fd2807SJeff Garzik return ofs; 1838c6fd2807SJeff Garzik } 1839c6fd2807SJeff Garzik 1840da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1841c6fd2807SJeff Garzik { 1842f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 1843f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 18440d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1845c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1846c6fd2807SJeff Garzik 1847da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1848da3dbb17STejun Heo *val = readl(addr + ofs); 1849da3dbb17STejun Heo return 0; 1850da3dbb17STejun Heo } else 1851da3dbb17STejun Heo return -EINVAL; 1852c6fd2807SJeff Garzik } 1853c6fd2807SJeff Garzik 1854da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1855c6fd2807SJeff Garzik { 1856f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 1857f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 18580d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1859c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1860c6fd2807SJeff Garzik 1861da3dbb17STejun Heo if (ofs != 0xffffffffU) { 18620d5ff566STejun Heo writelfl(val, addr + ofs); 1863da3dbb17STejun Heo return 0; 1864da3dbb17STejun Heo } else 1865da3dbb17STejun Heo return -EINVAL; 1866c6fd2807SJeff Garzik } 1867c6fd2807SJeff Garzik 18687bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio) 1869c6fd2807SJeff Garzik { 18707bb3c529SSaeed Bishara struct pci_dev *pdev = to_pci_dev(host->dev); 1871c6fd2807SJeff Garzik int early_5080; 1872c6fd2807SJeff Garzik 187344c10138SAuke Kok early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0); 1874c6fd2807SJeff Garzik 1875c6fd2807SJeff Garzik if (!early_5080) { 1876c6fd2807SJeff Garzik u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1877c6fd2807SJeff Garzik tmp |= (1 << 0); 1878c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1879c6fd2807SJeff Garzik } 1880c6fd2807SJeff Garzik 18817bb3c529SSaeed Bishara mv_reset_pci_bus(host, mmio); 1882c6fd2807SJeff Garzik } 1883c6fd2807SJeff Garzik 1884c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 1885c6fd2807SJeff Garzik { 1886c6fd2807SJeff Garzik writel(0x0fcfffff, mmio + MV_FLASH_CTL); 1887c6fd2807SJeff Garzik } 1888c6fd2807SJeff Garzik 1889c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 1890c6fd2807SJeff Garzik void __iomem *mmio) 1891c6fd2807SJeff Garzik { 1892c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, idx); 1893c6fd2807SJeff Garzik u32 tmp; 1894c6fd2807SJeff Garzik 1895c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1896c6fd2807SJeff Garzik 1897c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ 1898c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ 1899c6fd2807SJeff Garzik } 1900c6fd2807SJeff Garzik 1901c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 1902c6fd2807SJeff Garzik { 1903c6fd2807SJeff Garzik u32 tmp; 1904c6fd2807SJeff Garzik 1905c6fd2807SJeff Garzik writel(0, mmio + MV_GPIO_PORT_CTL); 1906c6fd2807SJeff Garzik 1907c6fd2807SJeff Garzik /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ 1908c6fd2807SJeff Garzik 1909c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1910c6fd2807SJeff Garzik tmp |= ~(1 << 0); 1911c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1912c6fd2807SJeff Garzik } 1913c6fd2807SJeff Garzik 1914c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 1915c6fd2807SJeff Garzik unsigned int port) 1916c6fd2807SJeff Garzik { 1917c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, port); 1918c6fd2807SJeff Garzik const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); 1919c6fd2807SJeff Garzik u32 tmp; 1920c6fd2807SJeff Garzik int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); 1921c6fd2807SJeff Garzik 1922c6fd2807SJeff Garzik if (fix_apm_sq) { 1923c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_LT_MODE); 1924c6fd2807SJeff Garzik tmp |= (1 << 19); 1925c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_LT_MODE); 1926c6fd2807SJeff Garzik 1927c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_CTL); 1928c6fd2807SJeff Garzik tmp &= ~0x3; 1929c6fd2807SJeff Garzik tmp |= 0x1; 1930c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_CTL); 1931c6fd2807SJeff Garzik } 1932c6fd2807SJeff Garzik 1933c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1934c6fd2807SJeff Garzik tmp &= ~mask; 1935c6fd2807SJeff Garzik tmp |= hpriv->signal[port].pre; 1936c6fd2807SJeff Garzik tmp |= hpriv->signal[port].amps; 1937c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_MODE); 1938c6fd2807SJeff Garzik } 1939c6fd2807SJeff Garzik 1940c6fd2807SJeff Garzik 1941c6fd2807SJeff Garzik #undef ZERO 1942c6fd2807SJeff Garzik #define ZERO(reg) writel(0, port_mmio + (reg)) 1943c6fd2807SJeff Garzik static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, 1944c6fd2807SJeff Garzik unsigned int port) 1945c6fd2807SJeff Garzik { 1946c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 1947c6fd2807SJeff Garzik 1948c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 1949c6fd2807SJeff Garzik 1950c6fd2807SJeff Garzik mv_channel_reset(hpriv, mmio, port); 1951c6fd2807SJeff Garzik 1952c6fd2807SJeff Garzik ZERO(0x028); /* command */ 1953c6fd2807SJeff Garzik writel(0x11f, port_mmio + EDMA_CFG_OFS); 1954c6fd2807SJeff Garzik ZERO(0x004); /* timer */ 1955c6fd2807SJeff Garzik ZERO(0x008); /* irq err cause */ 1956c6fd2807SJeff Garzik ZERO(0x00c); /* irq err mask */ 1957c6fd2807SJeff Garzik ZERO(0x010); /* rq bah */ 1958c6fd2807SJeff Garzik ZERO(0x014); /* rq inp */ 1959c6fd2807SJeff Garzik ZERO(0x018); /* rq outp */ 1960c6fd2807SJeff Garzik ZERO(0x01c); /* respq bah */ 1961c6fd2807SJeff Garzik ZERO(0x024); /* respq outp */ 1962c6fd2807SJeff Garzik ZERO(0x020); /* respq inp */ 1963c6fd2807SJeff Garzik ZERO(0x02c); /* test control */ 1964c6fd2807SJeff Garzik writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 1965c6fd2807SJeff Garzik } 1966c6fd2807SJeff Garzik #undef ZERO 1967c6fd2807SJeff Garzik 1968c6fd2807SJeff Garzik #define ZERO(reg) writel(0, hc_mmio + (reg)) 1969c6fd2807SJeff Garzik static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1970c6fd2807SJeff Garzik unsigned int hc) 1971c6fd2807SJeff Garzik { 1972c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1973c6fd2807SJeff Garzik u32 tmp; 1974c6fd2807SJeff Garzik 1975c6fd2807SJeff Garzik ZERO(0x00c); 1976c6fd2807SJeff Garzik ZERO(0x010); 1977c6fd2807SJeff Garzik ZERO(0x014); 1978c6fd2807SJeff Garzik ZERO(0x018); 1979c6fd2807SJeff Garzik 1980c6fd2807SJeff Garzik tmp = readl(hc_mmio + 0x20); 1981c6fd2807SJeff Garzik tmp &= 0x1c1c1c1c; 1982c6fd2807SJeff Garzik tmp |= 0x03030303; 1983c6fd2807SJeff Garzik writel(tmp, hc_mmio + 0x20); 1984c6fd2807SJeff Garzik } 1985c6fd2807SJeff Garzik #undef ZERO 1986c6fd2807SJeff Garzik 1987c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1988c6fd2807SJeff Garzik unsigned int n_hc) 1989c6fd2807SJeff Garzik { 1990c6fd2807SJeff Garzik unsigned int hc, port; 1991c6fd2807SJeff Garzik 1992c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 1993c6fd2807SJeff Garzik for (port = 0; port < MV_PORTS_PER_HC; port++) 1994c6fd2807SJeff Garzik mv5_reset_hc_port(hpriv, mmio, 1995c6fd2807SJeff Garzik (hc * MV_PORTS_PER_HC) + port); 1996c6fd2807SJeff Garzik 1997c6fd2807SJeff Garzik mv5_reset_one_hc(hpriv, mmio, hc); 1998c6fd2807SJeff Garzik } 1999c6fd2807SJeff Garzik 2000c6fd2807SJeff Garzik return 0; 2001c6fd2807SJeff Garzik } 2002c6fd2807SJeff Garzik 2003c6fd2807SJeff Garzik #undef ZERO 2004c6fd2807SJeff Garzik #define ZERO(reg) writel(0, mmio + (reg)) 20057bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio) 2006c6fd2807SJeff Garzik { 200702a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 2008c6fd2807SJeff Garzik u32 tmp; 2009c6fd2807SJeff Garzik 2010c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_MODE); 2011c6fd2807SJeff Garzik tmp &= 0xff00ffff; 2012c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_MODE); 2013c6fd2807SJeff Garzik 2014c6fd2807SJeff Garzik ZERO(MV_PCI_DISC_TIMER); 2015c6fd2807SJeff Garzik ZERO(MV_PCI_MSI_TRIGGER); 2016c6fd2807SJeff Garzik writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 2017c6fd2807SJeff Garzik ZERO(HC_MAIN_IRQ_MASK_OFS); 2018c6fd2807SJeff Garzik ZERO(MV_PCI_SERR_MASK); 201902a121daSMark Lord ZERO(hpriv->irq_cause_ofs); 202002a121daSMark Lord ZERO(hpriv->irq_mask_ofs); 2021c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_LOW_ADDRESS); 2022c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_HIGH_ADDRESS); 2023c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_ATTRIBUTE); 2024c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_COMMAND); 2025c6fd2807SJeff Garzik } 2026c6fd2807SJeff Garzik #undef ZERO 2027c6fd2807SJeff Garzik 2028c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 2029c6fd2807SJeff Garzik { 2030c6fd2807SJeff Garzik u32 tmp; 2031c6fd2807SJeff Garzik 2032c6fd2807SJeff Garzik mv5_reset_flash(hpriv, mmio); 2033c6fd2807SJeff Garzik 2034c6fd2807SJeff Garzik tmp = readl(mmio + MV_GPIO_PORT_CTL); 2035c6fd2807SJeff Garzik tmp &= 0x3; 2036c6fd2807SJeff Garzik tmp |= (1 << 5) | (1 << 6); 2037c6fd2807SJeff Garzik writel(tmp, mmio + MV_GPIO_PORT_CTL); 2038c6fd2807SJeff Garzik } 2039c6fd2807SJeff Garzik 2040c6fd2807SJeff Garzik /** 2041c6fd2807SJeff Garzik * mv6_reset_hc - Perform the 6xxx global soft reset 2042c6fd2807SJeff Garzik * @mmio: base address of the HBA 2043c6fd2807SJeff Garzik * 2044c6fd2807SJeff Garzik * This routine only applies to 6xxx parts. 2045c6fd2807SJeff Garzik * 2046c6fd2807SJeff Garzik * LOCKING: 2047c6fd2807SJeff Garzik * Inherited from caller. 2048c6fd2807SJeff Garzik */ 2049c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 2050c6fd2807SJeff Garzik unsigned int n_hc) 2051c6fd2807SJeff Garzik { 2052c6fd2807SJeff Garzik void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS; 2053c6fd2807SJeff Garzik int i, rc = 0; 2054c6fd2807SJeff Garzik u32 t; 2055c6fd2807SJeff Garzik 2056c6fd2807SJeff Garzik /* Following procedure defined in PCI "main command and status 2057c6fd2807SJeff Garzik * register" table. 2058c6fd2807SJeff Garzik */ 2059c6fd2807SJeff Garzik t = readl(reg); 2060c6fd2807SJeff Garzik writel(t | STOP_PCI_MASTER, reg); 2061c6fd2807SJeff Garzik 2062c6fd2807SJeff Garzik for (i = 0; i < 1000; i++) { 2063c6fd2807SJeff Garzik udelay(1); 2064c6fd2807SJeff Garzik t = readl(reg); 20652dcb407eSJeff Garzik if (PCI_MASTER_EMPTY & t) 2066c6fd2807SJeff Garzik break; 2067c6fd2807SJeff Garzik } 2068c6fd2807SJeff Garzik if (!(PCI_MASTER_EMPTY & t)) { 2069c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); 2070c6fd2807SJeff Garzik rc = 1; 2071c6fd2807SJeff Garzik goto done; 2072c6fd2807SJeff Garzik } 2073c6fd2807SJeff Garzik 2074c6fd2807SJeff Garzik /* set reset */ 2075c6fd2807SJeff Garzik i = 5; 2076c6fd2807SJeff Garzik do { 2077c6fd2807SJeff Garzik writel(t | GLOB_SFT_RST, reg); 2078c6fd2807SJeff Garzik t = readl(reg); 2079c6fd2807SJeff Garzik udelay(1); 2080c6fd2807SJeff Garzik } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 2081c6fd2807SJeff Garzik 2082c6fd2807SJeff Garzik if (!(GLOB_SFT_RST & t)) { 2083c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't set global reset\n"); 2084c6fd2807SJeff Garzik rc = 1; 2085c6fd2807SJeff Garzik goto done; 2086c6fd2807SJeff Garzik } 2087c6fd2807SJeff Garzik 2088c6fd2807SJeff Garzik /* clear reset and *reenable the PCI master* (not mentioned in spec) */ 2089c6fd2807SJeff Garzik i = 5; 2090c6fd2807SJeff Garzik do { 2091c6fd2807SJeff Garzik writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); 2092c6fd2807SJeff Garzik t = readl(reg); 2093c6fd2807SJeff Garzik udelay(1); 2094c6fd2807SJeff Garzik } while ((GLOB_SFT_RST & t) && (i-- > 0)); 2095c6fd2807SJeff Garzik 2096c6fd2807SJeff Garzik if (GLOB_SFT_RST & t) { 2097c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 2098c6fd2807SJeff Garzik rc = 1; 2099c6fd2807SJeff Garzik } 2100c6fd2807SJeff Garzik done: 2101c6fd2807SJeff Garzik return rc; 2102c6fd2807SJeff Garzik } 2103c6fd2807SJeff Garzik 2104c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 2105c6fd2807SJeff Garzik void __iomem *mmio) 2106c6fd2807SJeff Garzik { 2107c6fd2807SJeff Garzik void __iomem *port_mmio; 2108c6fd2807SJeff Garzik u32 tmp; 2109c6fd2807SJeff Garzik 2110c6fd2807SJeff Garzik tmp = readl(mmio + MV_RESET_CFG); 2111c6fd2807SJeff Garzik if ((tmp & (1 << 0)) == 0) { 2112c6fd2807SJeff Garzik hpriv->signal[idx].amps = 0x7 << 8; 2113c6fd2807SJeff Garzik hpriv->signal[idx].pre = 0x1 << 5; 2114c6fd2807SJeff Garzik return; 2115c6fd2807SJeff Garzik } 2116c6fd2807SJeff Garzik 2117c6fd2807SJeff Garzik port_mmio = mv_port_base(mmio, idx); 2118c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE2); 2119c6fd2807SJeff Garzik 2120c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 2121c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 2122c6fd2807SJeff Garzik } 2123c6fd2807SJeff Garzik 2124c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 2125c6fd2807SJeff Garzik { 2126c6fd2807SJeff Garzik writel(0x00000060, mmio + MV_GPIO_PORT_CTL); 2127c6fd2807SJeff Garzik } 2128c6fd2807SJeff Garzik 2129c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 2130c6fd2807SJeff Garzik unsigned int port) 2131c6fd2807SJeff Garzik { 2132c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2133c6fd2807SJeff Garzik 2134c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2135c6fd2807SJeff Garzik int fix_phy_mode2 = 2136c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2137c6fd2807SJeff Garzik int fix_phy_mode4 = 2138c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2139c6fd2807SJeff Garzik u32 m2, tmp; 2140c6fd2807SJeff Garzik 2141c6fd2807SJeff Garzik if (fix_phy_mode2) { 2142c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2143c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2144c6fd2807SJeff Garzik m2 |= (1 << 31); 2145c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2146c6fd2807SJeff Garzik 2147c6fd2807SJeff Garzik udelay(200); 2148c6fd2807SJeff Garzik 2149c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2150c6fd2807SJeff Garzik m2 &= ~((1 << 16) | (1 << 31)); 2151c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2152c6fd2807SJeff Garzik 2153c6fd2807SJeff Garzik udelay(200); 2154c6fd2807SJeff Garzik } 2155c6fd2807SJeff Garzik 2156c6fd2807SJeff Garzik /* who knows what this magic does */ 2157c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE3); 2158c6fd2807SJeff Garzik tmp &= ~0x7F800000; 2159c6fd2807SJeff Garzik tmp |= 0x2A800000; 2160c6fd2807SJeff Garzik writel(tmp, port_mmio + PHY_MODE3); 2161c6fd2807SJeff Garzik 2162c6fd2807SJeff Garzik if (fix_phy_mode4) { 2163c6fd2807SJeff Garzik u32 m4; 2164c6fd2807SJeff Garzik 2165c6fd2807SJeff Garzik m4 = readl(port_mmio + PHY_MODE4); 2166c6fd2807SJeff Garzik 2167c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2168c6fd2807SJeff Garzik tmp = readl(port_mmio + 0x310); 2169c6fd2807SJeff Garzik 2170c6fd2807SJeff Garzik m4 = (m4 & ~(1 << 1)) | (1 << 0); 2171c6fd2807SJeff Garzik 2172c6fd2807SJeff Garzik writel(m4, port_mmio + PHY_MODE4); 2173c6fd2807SJeff Garzik 2174c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2175c6fd2807SJeff Garzik writel(tmp, port_mmio + 0x310); 2176c6fd2807SJeff Garzik } 2177c6fd2807SJeff Garzik 2178c6fd2807SJeff Garzik /* Revert values of pre-emphasis and signal amps to the saved ones */ 2179c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2180c6fd2807SJeff Garzik 2181c6fd2807SJeff Garzik m2 &= ~MV_M2_PREAMP_MASK; 2182c6fd2807SJeff Garzik m2 |= hpriv->signal[port].amps; 2183c6fd2807SJeff Garzik m2 |= hpriv->signal[port].pre; 2184c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2185c6fd2807SJeff Garzik 2186c6fd2807SJeff Garzik /* according to mvSata 3.6.1, some IIE values are fixed */ 2187c6fd2807SJeff Garzik if (IS_GEN_IIE(hpriv)) { 2188c6fd2807SJeff Garzik m2 &= ~0xC30FF01F; 2189c6fd2807SJeff Garzik m2 |= 0x0000900F; 2190c6fd2807SJeff Garzik } 2191c6fd2807SJeff Garzik 2192c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2193c6fd2807SJeff Garzik } 2194c6fd2807SJeff Garzik 2195f351b2d6SSaeed Bishara /* TODO: use the generic LED interface to configure the SATA Presence */ 2196f351b2d6SSaeed Bishara /* & Acitivy LEDs on the board */ 2197f351b2d6SSaeed Bishara static void mv_soc_enable_leds(struct mv_host_priv *hpriv, 2198f351b2d6SSaeed Bishara void __iomem *mmio) 2199f351b2d6SSaeed Bishara { 2200f351b2d6SSaeed Bishara return; 2201f351b2d6SSaeed Bishara } 2202f351b2d6SSaeed Bishara 2203f351b2d6SSaeed Bishara static void mv_soc_read_preamp(struct mv_host_priv *hpriv, int idx, 2204f351b2d6SSaeed Bishara void __iomem *mmio) 2205f351b2d6SSaeed Bishara { 2206f351b2d6SSaeed Bishara void __iomem *port_mmio; 2207f351b2d6SSaeed Bishara u32 tmp; 2208f351b2d6SSaeed Bishara 2209f351b2d6SSaeed Bishara port_mmio = mv_port_base(mmio, idx); 2210f351b2d6SSaeed Bishara tmp = readl(port_mmio + PHY_MODE2); 2211f351b2d6SSaeed Bishara 2212f351b2d6SSaeed Bishara hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 2213f351b2d6SSaeed Bishara hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 2214f351b2d6SSaeed Bishara } 2215f351b2d6SSaeed Bishara 2216f351b2d6SSaeed Bishara #undef ZERO 2217f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, port_mmio + (reg)) 2218f351b2d6SSaeed Bishara static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv, 2219f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int port) 2220f351b2d6SSaeed Bishara { 2221f351b2d6SSaeed Bishara void __iomem *port_mmio = mv_port_base(mmio, port); 2222f351b2d6SSaeed Bishara 2223f351b2d6SSaeed Bishara writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 2224f351b2d6SSaeed Bishara 2225f351b2d6SSaeed Bishara mv_channel_reset(hpriv, mmio, port); 2226f351b2d6SSaeed Bishara 2227f351b2d6SSaeed Bishara ZERO(0x028); /* command */ 2228f351b2d6SSaeed Bishara writel(0x101f, port_mmio + EDMA_CFG_OFS); 2229f351b2d6SSaeed Bishara ZERO(0x004); /* timer */ 2230f351b2d6SSaeed Bishara ZERO(0x008); /* irq err cause */ 2231f351b2d6SSaeed Bishara ZERO(0x00c); /* irq err mask */ 2232f351b2d6SSaeed Bishara ZERO(0x010); /* rq bah */ 2233f351b2d6SSaeed Bishara ZERO(0x014); /* rq inp */ 2234f351b2d6SSaeed Bishara ZERO(0x018); /* rq outp */ 2235f351b2d6SSaeed Bishara ZERO(0x01c); /* respq bah */ 2236f351b2d6SSaeed Bishara ZERO(0x024); /* respq outp */ 2237f351b2d6SSaeed Bishara ZERO(0x020); /* respq inp */ 2238f351b2d6SSaeed Bishara ZERO(0x02c); /* test control */ 2239f351b2d6SSaeed Bishara writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 2240f351b2d6SSaeed Bishara } 2241f351b2d6SSaeed Bishara 2242f351b2d6SSaeed Bishara #undef ZERO 2243f351b2d6SSaeed Bishara 2244f351b2d6SSaeed Bishara #define ZERO(reg) writel(0, hc_mmio + (reg)) 2245f351b2d6SSaeed Bishara static void mv_soc_reset_one_hc(struct mv_host_priv *hpriv, 2246f351b2d6SSaeed Bishara void __iomem *mmio) 2247f351b2d6SSaeed Bishara { 2248f351b2d6SSaeed Bishara void __iomem *hc_mmio = mv_hc_base(mmio, 0); 2249f351b2d6SSaeed Bishara 2250f351b2d6SSaeed Bishara ZERO(0x00c); 2251f351b2d6SSaeed Bishara ZERO(0x010); 2252f351b2d6SSaeed Bishara ZERO(0x014); 2253f351b2d6SSaeed Bishara 2254f351b2d6SSaeed Bishara } 2255f351b2d6SSaeed Bishara 2256f351b2d6SSaeed Bishara #undef ZERO 2257f351b2d6SSaeed Bishara 2258f351b2d6SSaeed Bishara static int mv_soc_reset_hc(struct mv_host_priv *hpriv, 2259f351b2d6SSaeed Bishara void __iomem *mmio, unsigned int n_hc) 2260f351b2d6SSaeed Bishara { 2261f351b2d6SSaeed Bishara unsigned int port; 2262f351b2d6SSaeed Bishara 2263f351b2d6SSaeed Bishara for (port = 0; port < hpriv->n_ports; port++) 2264f351b2d6SSaeed Bishara mv_soc_reset_hc_port(hpriv, mmio, port); 2265f351b2d6SSaeed Bishara 2266f351b2d6SSaeed Bishara mv_soc_reset_one_hc(hpriv, mmio); 2267f351b2d6SSaeed Bishara 2268f351b2d6SSaeed Bishara return 0; 2269f351b2d6SSaeed Bishara } 2270f351b2d6SSaeed Bishara 2271f351b2d6SSaeed Bishara static void mv_soc_reset_flash(struct mv_host_priv *hpriv, 2272f351b2d6SSaeed Bishara void __iomem *mmio) 2273f351b2d6SSaeed Bishara { 2274f351b2d6SSaeed Bishara return; 2275f351b2d6SSaeed Bishara } 2276f351b2d6SSaeed Bishara 2277f351b2d6SSaeed Bishara static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio) 2278f351b2d6SSaeed Bishara { 2279f351b2d6SSaeed Bishara return; 2280f351b2d6SSaeed Bishara } 2281f351b2d6SSaeed Bishara 2282c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 2283c6fd2807SJeff Garzik unsigned int port_no) 2284c6fd2807SJeff Garzik { 2285c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port_no); 2286c6fd2807SJeff Garzik 2287c6fd2807SJeff Garzik writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); 2288c6fd2807SJeff Garzik 2289ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2290c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2291c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2292c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2293c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2294c6fd2807SJeff Garzik } 2295c6fd2807SJeff Garzik 2296c6fd2807SJeff Garzik udelay(25); /* allow reset propagation */ 2297c6fd2807SJeff Garzik 2298c6fd2807SJeff Garzik /* Spec never mentions clearing the bit. Marvell's driver does 2299c6fd2807SJeff Garzik * clear the bit, however. 2300c6fd2807SJeff Garzik */ 2301c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_CMD_OFS); 2302c6fd2807SJeff Garzik 2303c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port_no); 2304c6fd2807SJeff Garzik 2305ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2306c6fd2807SJeff Garzik mdelay(1); 2307c6fd2807SJeff Garzik } 2308c6fd2807SJeff Garzik 2309c6fd2807SJeff Garzik /** 2310bdd4dddeSJeff Garzik * mv_phy_reset - Perform eDMA reset followed by COMRESET 2311c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 2312c6fd2807SJeff Garzik * 2313c6fd2807SJeff Garzik * Part of this is taken from __sata_phy_reset and modified to 2314c6fd2807SJeff Garzik * not sleep since this routine gets called from interrupt level. 2315c6fd2807SJeff Garzik * 2316c6fd2807SJeff Garzik * LOCKING: 2317c6fd2807SJeff Garzik * Inherited from caller. This is coded to safe to call at 2318c6fd2807SJeff Garzik * interrupt level, i.e. it does not sleep. 2319c6fd2807SJeff Garzik */ 2320bdd4dddeSJeff Garzik static void mv_phy_reset(struct ata_port *ap, unsigned int *class, 2321bdd4dddeSJeff Garzik unsigned long deadline) 2322c6fd2807SJeff Garzik { 2323c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 2324cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2325c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2326c6fd2807SJeff Garzik int retry = 5; 2327c6fd2807SJeff Garzik u32 sstatus; 2328c6fd2807SJeff Garzik 2329c6fd2807SJeff Garzik VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 2330c6fd2807SJeff Garzik 2331da3dbb17STejun Heo #ifdef DEBUG 2332da3dbb17STejun Heo { 2333da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2334da3dbb17STejun Heo 2335da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2336da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2337da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2338c6fd2807SJeff Garzik DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 23392d79ab8fSSaeed Bishara "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2340da3dbb17STejun Heo } 2341da3dbb17STejun Heo #endif 2342c6fd2807SJeff Garzik 2343c6fd2807SJeff Garzik /* Issue COMRESET via SControl */ 2344c6fd2807SJeff Garzik comreset_retry: 2345936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x301); 2346bdd4dddeSJeff Garzik msleep(1); 2347c6fd2807SJeff Garzik 2348936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x300); 2349bdd4dddeSJeff Garzik msleep(20); 2350c6fd2807SJeff Garzik 2351c6fd2807SJeff Garzik do { 2352936fd732STejun Heo sata_scr_read(&ap->link, SCR_STATUS, &sstatus); 2353dd1dc802SJeff Garzik if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 2354c6fd2807SJeff Garzik break; 2355c6fd2807SJeff Garzik 2356bdd4dddeSJeff Garzik msleep(1); 2357c5d3e45aSJeff Garzik } while (time_before(jiffies, deadline)); 2358c6fd2807SJeff Garzik 2359c6fd2807SJeff Garzik /* work around errata */ 2360ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv) && 2361c6fd2807SJeff Garzik (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && 2362c6fd2807SJeff Garzik (retry-- > 0)) 2363c6fd2807SJeff Garzik goto comreset_retry; 2364c6fd2807SJeff Garzik 2365da3dbb17STejun Heo #ifdef DEBUG 2366da3dbb17STejun Heo { 2367da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2368da3dbb17STejun Heo 2369da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2370da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2371da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2372c6fd2807SJeff Garzik DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " 2373da3dbb17STejun Heo "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2374da3dbb17STejun Heo } 2375da3dbb17STejun Heo #endif 2376c6fd2807SJeff Garzik 2377936fd732STejun Heo if (ata_link_offline(&ap->link)) { 2378bdd4dddeSJeff Garzik *class = ATA_DEV_NONE; 2379c6fd2807SJeff Garzik return; 2380c6fd2807SJeff Garzik } 2381c6fd2807SJeff Garzik 2382c6fd2807SJeff Garzik /* even after SStatus reflects that device is ready, 2383c6fd2807SJeff Garzik * it seems to take a while for link to be fully 2384c6fd2807SJeff Garzik * established (and thus Status no longer 0x80/0x7F), 2385c6fd2807SJeff Garzik * so we poll a bit for that, here. 2386c6fd2807SJeff Garzik */ 2387c6fd2807SJeff Garzik retry = 20; 2388c6fd2807SJeff Garzik while (1) { 2389c6fd2807SJeff Garzik u8 drv_stat = ata_check_status(ap); 2390c6fd2807SJeff Garzik if ((drv_stat != 0x80) && (drv_stat != 0x7f)) 2391c6fd2807SJeff Garzik break; 2392bdd4dddeSJeff Garzik msleep(500); 2393c6fd2807SJeff Garzik if (retry-- <= 0) 2394c6fd2807SJeff Garzik break; 2395bdd4dddeSJeff Garzik if (time_after(jiffies, deadline)) 2396bdd4dddeSJeff Garzik break; 2397c6fd2807SJeff Garzik } 2398c6fd2807SJeff Garzik 2399bdd4dddeSJeff Garzik /* FIXME: if we passed the deadline, the following 2400bdd4dddeSJeff Garzik * code probably produces an invalid result 2401bdd4dddeSJeff Garzik */ 2402c6fd2807SJeff Garzik 2403bdd4dddeSJeff Garzik /* finally, read device signature from TF registers */ 24043f19859eSTejun Heo *class = ata_dev_try_classify(ap->link.device, 1, NULL); 2405c6fd2807SJeff Garzik 2406c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2407c6fd2807SJeff Garzik 2408bdd4dddeSJeff Garzik WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN); 2409c6fd2807SJeff Garzik 2410c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 2411c6fd2807SJeff Garzik } 2412c6fd2807SJeff Garzik 2413cc0680a5STejun Heo static int mv_prereset(struct ata_link *link, unsigned long deadline) 2414c6fd2807SJeff Garzik { 2415cc0680a5STejun Heo struct ata_port *ap = link->ap; 2416bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 2417bdd4dddeSJeff Garzik 2418cf480626STejun Heo mv_stop_dma(ap); 2419bdd4dddeSJeff Garzik 2420cf480626STejun Heo if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) 2421bdd4dddeSJeff Garzik pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET; 2422c6fd2807SJeff Garzik 2423bdd4dddeSJeff Garzik return 0; 2424bdd4dddeSJeff Garzik } 2425bdd4dddeSJeff Garzik 2426cc0680a5STejun Heo static int mv_hardreset(struct ata_link *link, unsigned int *class, 2427bdd4dddeSJeff Garzik unsigned long deadline) 2428bdd4dddeSJeff Garzik { 2429cc0680a5STejun Heo struct ata_port *ap = link->ap; 2430bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2431f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2432bdd4dddeSJeff Garzik 2433bdd4dddeSJeff Garzik mv_stop_dma(ap); 2434bdd4dddeSJeff Garzik 2435bdd4dddeSJeff Garzik mv_channel_reset(hpriv, mmio, ap->port_no); 2436bdd4dddeSJeff Garzik 2437bdd4dddeSJeff Garzik mv_phy_reset(ap, class, deadline); 2438bdd4dddeSJeff Garzik 2439bdd4dddeSJeff Garzik return 0; 2440bdd4dddeSJeff Garzik } 2441bdd4dddeSJeff Garzik 2442cc0680a5STejun Heo static void mv_postreset(struct ata_link *link, unsigned int *classes) 2443bdd4dddeSJeff Garzik { 2444cc0680a5STejun Heo struct ata_port *ap = link->ap; 2445bdd4dddeSJeff Garzik u32 serr; 2446bdd4dddeSJeff Garzik 2447bdd4dddeSJeff Garzik /* print link status */ 2448cc0680a5STejun Heo sata_print_link_status(link); 2449bdd4dddeSJeff Garzik 2450bdd4dddeSJeff Garzik /* clear SError */ 2451cc0680a5STejun Heo sata_scr_read(link, SCR_ERROR, &serr); 2452cc0680a5STejun Heo sata_scr_write_flush(link, SCR_ERROR, serr); 2453bdd4dddeSJeff Garzik 2454bdd4dddeSJeff Garzik /* bail out if no device is present */ 2455bdd4dddeSJeff Garzik if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { 2456bdd4dddeSJeff Garzik DPRINTK("EXIT, no device\n"); 2457bdd4dddeSJeff Garzik return; 2458bdd4dddeSJeff Garzik } 2459bdd4dddeSJeff Garzik 2460bdd4dddeSJeff Garzik /* set up device control */ 2461bdd4dddeSJeff Garzik iowrite8(ap->ctl, ap->ioaddr.ctl_addr); 2462bdd4dddeSJeff Garzik } 2463bdd4dddeSJeff Garzik 2464bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap) 2465bdd4dddeSJeff Garzik { 2466bdd4dddeSJeff Garzik ata_do_eh(ap, mv_prereset, ata_std_softreset, 2467bdd4dddeSJeff Garzik mv_hardreset, mv_postreset); 2468bdd4dddeSJeff Garzik } 2469bdd4dddeSJeff Garzik 2470bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap) 2471c6fd2807SJeff Garzik { 2472f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 2473bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2474bdd4dddeSJeff Garzik u32 tmp, mask; 2475bdd4dddeSJeff Garzik unsigned int shift; 2476c6fd2807SJeff Garzik 2477bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2478c6fd2807SJeff Garzik 2479bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2480bdd4dddeSJeff Garzik if (hc > 0) 2481bdd4dddeSJeff Garzik shift++; 2482c6fd2807SJeff Garzik 2483bdd4dddeSJeff Garzik mask = 0x3 << shift; 2484c6fd2807SJeff Garzik 2485bdd4dddeSJeff Garzik /* disable assertion of portN err, done events */ 2486f351b2d6SSaeed Bishara tmp = readl(hpriv->main_mask_reg_addr); 2487f351b2d6SSaeed Bishara writelfl(tmp & ~mask, hpriv->main_mask_reg_addr); 2488c6fd2807SJeff Garzik } 2489bdd4dddeSJeff Garzik 2490bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap) 2491bdd4dddeSJeff Garzik { 2492f351b2d6SSaeed Bishara struct mv_host_priv *hpriv = ap->host->private_data; 2493f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2494bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2495bdd4dddeSJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2496bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2497bdd4dddeSJeff Garzik u32 tmp, mask, hc_irq_cause; 2498bdd4dddeSJeff Garzik unsigned int shift, hc_port_no = ap->port_no; 2499bdd4dddeSJeff Garzik 2500bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2501bdd4dddeSJeff Garzik 2502bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2503bdd4dddeSJeff Garzik if (hc > 0) { 2504bdd4dddeSJeff Garzik shift++; 2505bdd4dddeSJeff Garzik hc_port_no -= 4; 2506bdd4dddeSJeff Garzik } 2507bdd4dddeSJeff Garzik 2508bdd4dddeSJeff Garzik mask = 0x3 << shift; 2509bdd4dddeSJeff Garzik 2510bdd4dddeSJeff Garzik /* clear EDMA errors on this port */ 2511bdd4dddeSJeff Garzik writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2512bdd4dddeSJeff Garzik 2513bdd4dddeSJeff Garzik /* clear pending irq events */ 2514bdd4dddeSJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 2515bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */ 2516bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */ 2517bdd4dddeSJeff Garzik writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 2518bdd4dddeSJeff Garzik 2519bdd4dddeSJeff Garzik /* enable assertion of portN err, done events */ 2520f351b2d6SSaeed Bishara tmp = readl(hpriv->main_mask_reg_addr); 2521f351b2d6SSaeed Bishara writelfl(tmp | mask, hpriv->main_mask_reg_addr); 2522c6fd2807SJeff Garzik } 2523c6fd2807SJeff Garzik 2524c6fd2807SJeff Garzik /** 2525c6fd2807SJeff Garzik * mv_port_init - Perform some early initialization on a single port. 2526c6fd2807SJeff Garzik * @port: libata data structure storing shadow register addresses 2527c6fd2807SJeff Garzik * @port_mmio: base address of the port 2528c6fd2807SJeff Garzik * 2529c6fd2807SJeff Garzik * Initialize shadow register mmio addresses, clear outstanding 2530c6fd2807SJeff Garzik * interrupts on the port, and unmask interrupts for the future 2531c6fd2807SJeff Garzik * start of the port. 2532c6fd2807SJeff Garzik * 2533c6fd2807SJeff Garzik * LOCKING: 2534c6fd2807SJeff Garzik * Inherited from caller. 2535c6fd2807SJeff Garzik */ 2536c6fd2807SJeff Garzik static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 2537c6fd2807SJeff Garzik { 25380d5ff566STejun Heo void __iomem *shd_base = port_mmio + SHD_BLK_OFS; 2539c6fd2807SJeff Garzik unsigned serr_ofs; 2540c6fd2807SJeff Garzik 2541c6fd2807SJeff Garzik /* PIO related setup 2542c6fd2807SJeff Garzik */ 2543c6fd2807SJeff Garzik port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); 2544c6fd2807SJeff Garzik port->error_addr = 2545c6fd2807SJeff Garzik port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); 2546c6fd2807SJeff Garzik port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); 2547c6fd2807SJeff Garzik port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); 2548c6fd2807SJeff Garzik port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); 2549c6fd2807SJeff Garzik port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); 2550c6fd2807SJeff Garzik port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); 2551c6fd2807SJeff Garzik port->status_addr = 2552c6fd2807SJeff Garzik port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); 2553c6fd2807SJeff Garzik /* special case: control/altstatus doesn't have ATA_REG_ address */ 2554c6fd2807SJeff Garzik port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; 2555c6fd2807SJeff Garzik 2556c6fd2807SJeff Garzik /* unused: */ 25578d9db2d2SRandy Dunlap port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL; 2558c6fd2807SJeff Garzik 2559c6fd2807SJeff Garzik /* Clear any currently outstanding port interrupt conditions */ 2560c6fd2807SJeff Garzik serr_ofs = mv_scr_offset(SCR_ERROR); 2561c6fd2807SJeff Garzik writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs); 2562c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2563c6fd2807SJeff Garzik 2564646a4da5SMark Lord /* unmask all non-transient EDMA error interrupts */ 2565646a4da5SMark Lord writelfl(~EDMA_ERR_IRQ_TRANSIENT, port_mmio + EDMA_ERR_IRQ_MASK_OFS); 2566c6fd2807SJeff Garzik 2567c6fd2807SJeff Garzik VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 2568c6fd2807SJeff Garzik readl(port_mmio + EDMA_CFG_OFS), 2569c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), 2570c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); 2571c6fd2807SJeff Garzik } 2572c6fd2807SJeff Garzik 25734447d351STejun Heo static int mv_chip_id(struct ata_host *host, unsigned int board_idx) 2574c6fd2807SJeff Garzik { 25754447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 25764447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2577c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2578c6fd2807SJeff Garzik 2579c6fd2807SJeff Garzik switch (board_idx) { 2580c6fd2807SJeff Garzik case chip_5080: 2581c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2582ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2583c6fd2807SJeff Garzik 258444c10138SAuke Kok switch (pdev->revision) { 2585c6fd2807SJeff Garzik case 0x1: 2586c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2587c6fd2807SJeff Garzik break; 2588c6fd2807SJeff Garzik case 0x3: 2589c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2590c6fd2807SJeff Garzik break; 2591c6fd2807SJeff Garzik default: 2592c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2593c6fd2807SJeff Garzik "Applying 50XXB2 workarounds to unknown rev\n"); 2594c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2595c6fd2807SJeff Garzik break; 2596c6fd2807SJeff Garzik } 2597c6fd2807SJeff Garzik break; 2598c6fd2807SJeff Garzik 2599c6fd2807SJeff Garzik case chip_504x: 2600c6fd2807SJeff Garzik case chip_508x: 2601c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2602ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2603c6fd2807SJeff Garzik 260444c10138SAuke Kok switch (pdev->revision) { 2605c6fd2807SJeff Garzik case 0x0: 2606c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2607c6fd2807SJeff Garzik break; 2608c6fd2807SJeff Garzik case 0x3: 2609c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2610c6fd2807SJeff Garzik break; 2611c6fd2807SJeff Garzik default: 2612c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2613c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2614c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2615c6fd2807SJeff Garzik break; 2616c6fd2807SJeff Garzik } 2617c6fd2807SJeff Garzik break; 2618c6fd2807SJeff Garzik 2619c6fd2807SJeff Garzik case chip_604x: 2620c6fd2807SJeff Garzik case chip_608x: 2621c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2622ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_II; 2623c6fd2807SJeff Garzik 262444c10138SAuke Kok switch (pdev->revision) { 2625c6fd2807SJeff Garzik case 0x7: 2626c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2627c6fd2807SJeff Garzik break; 2628c6fd2807SJeff Garzik case 0x9: 2629c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2630c6fd2807SJeff Garzik break; 2631c6fd2807SJeff Garzik default: 2632c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2633c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2634c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2635c6fd2807SJeff Garzik break; 2636c6fd2807SJeff Garzik } 2637c6fd2807SJeff Garzik break; 2638c6fd2807SJeff Garzik 2639c6fd2807SJeff Garzik case chip_7042: 264002a121daSMark Lord hp_flags |= MV_HP_PCIE; 2641306b30f7SMark Lord if (pdev->vendor == PCI_VENDOR_ID_TTI && 2642306b30f7SMark Lord (pdev->device == 0x2300 || pdev->device == 0x2310)) 2643306b30f7SMark Lord { 26444e520033SMark Lord /* 26454e520033SMark Lord * Highpoint RocketRAID PCIe 23xx series cards: 26464e520033SMark Lord * 26474e520033SMark Lord * Unconfigured drives are treated as "Legacy" 26484e520033SMark Lord * by the BIOS, and it overwrites sector 8 with 26494e520033SMark Lord * a "Lgcy" metadata block prior to Linux boot. 26504e520033SMark Lord * 26514e520033SMark Lord * Configured drives (RAID or JBOD) leave sector 8 26524e520033SMark Lord * alone, but instead overwrite a high numbered 26534e520033SMark Lord * sector for the RAID metadata. This sector can 26544e520033SMark Lord * be determined exactly, by truncating the physical 26554e520033SMark Lord * drive capacity to a nice even GB value. 26564e520033SMark Lord * 26574e520033SMark Lord * RAID metadata is at: (dev->n_sectors & ~0xfffff) 26584e520033SMark Lord * 26594e520033SMark Lord * Warn the user, lest they think we're just buggy. 26604e520033SMark Lord */ 26614e520033SMark Lord printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID" 26624e520033SMark Lord " BIOS CORRUPTS DATA on all attached drives," 26634e520033SMark Lord " regardless of if/how they are configured." 26644e520033SMark Lord " BEWARE!\n"); 26654e520033SMark Lord printk(KERN_WARNING DRV_NAME ": For data safety, do not" 26664e520033SMark Lord " use sectors 8-9 on \"Legacy\" drives," 26674e520033SMark Lord " and avoid the final two gigabytes on" 26684e520033SMark Lord " all RocketRAID BIOS initialized drives.\n"); 2669306b30f7SMark Lord } 2670c6fd2807SJeff Garzik case chip_6042: 2671c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2672c6fd2807SJeff Garzik hp_flags |= MV_HP_GEN_IIE; 2673c6fd2807SJeff Garzik 267444c10138SAuke Kok switch (pdev->revision) { 2675c6fd2807SJeff Garzik case 0x0: 2676c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_XX42A0; 2677c6fd2807SJeff Garzik break; 2678c6fd2807SJeff Garzik case 0x1: 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 60X1C0 workarounds to unknown rev\n"); 2684c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2685c6fd2807SJeff Garzik break; 2686c6fd2807SJeff Garzik } 2687c6fd2807SJeff Garzik break; 2688f351b2d6SSaeed Bishara case chip_soc: 2689f351b2d6SSaeed Bishara hpriv->ops = &mv_soc_ops; 2690f351b2d6SSaeed Bishara hp_flags |= MV_HP_ERRATA_60X1C0; 2691f351b2d6SSaeed Bishara break; 2692c6fd2807SJeff Garzik 2693c6fd2807SJeff Garzik default: 2694f351b2d6SSaeed Bishara dev_printk(KERN_ERR, host->dev, 26955796d1c4SJeff Garzik "BUG: invalid board index %u\n", board_idx); 2696c6fd2807SJeff Garzik return 1; 2697c6fd2807SJeff Garzik } 2698c6fd2807SJeff Garzik 2699c6fd2807SJeff Garzik hpriv->hp_flags = hp_flags; 270002a121daSMark Lord if (hp_flags & MV_HP_PCIE) { 270102a121daSMark Lord hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS; 270202a121daSMark Lord hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS; 270302a121daSMark Lord hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS; 270402a121daSMark Lord } else { 270502a121daSMark Lord hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS; 270602a121daSMark Lord hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS; 270702a121daSMark Lord hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS; 270802a121daSMark Lord } 2709c6fd2807SJeff Garzik 2710c6fd2807SJeff Garzik return 0; 2711c6fd2807SJeff Garzik } 2712c6fd2807SJeff Garzik 2713c6fd2807SJeff Garzik /** 2714c6fd2807SJeff Garzik * mv_init_host - Perform some early initialization of the host. 27154447d351STejun Heo * @host: ATA host to initialize 27164447d351STejun Heo * @board_idx: controller index 2717c6fd2807SJeff Garzik * 2718c6fd2807SJeff Garzik * If possible, do an early global reset of the host. Then do 2719c6fd2807SJeff Garzik * our port init and clear/unmask all/relevant host interrupts. 2720c6fd2807SJeff Garzik * 2721c6fd2807SJeff Garzik * LOCKING: 2722c6fd2807SJeff Garzik * Inherited from caller. 2723c6fd2807SJeff Garzik */ 27244447d351STejun Heo static int mv_init_host(struct ata_host *host, unsigned int board_idx) 2725c6fd2807SJeff Garzik { 2726c6fd2807SJeff Garzik int rc = 0, n_hc, port, hc; 27274447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2728f351b2d6SSaeed Bishara void __iomem *mmio = hpriv->base; 2729c6fd2807SJeff Garzik 27304447d351STejun Heo rc = mv_chip_id(host, board_idx); 2731c6fd2807SJeff Garzik if (rc) 2732c6fd2807SJeff Garzik goto done; 2733c6fd2807SJeff Garzik 2734f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2735f351b2d6SSaeed Bishara hpriv->main_cause_reg_addr = hpriv->base + 2736f351b2d6SSaeed Bishara HC_MAIN_IRQ_CAUSE_OFS; 2737f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr = hpriv->base + HC_MAIN_IRQ_MASK_OFS; 2738f351b2d6SSaeed Bishara } else { 2739f351b2d6SSaeed Bishara hpriv->main_cause_reg_addr = hpriv->base + 2740f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_CAUSE_OFS; 2741f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr = hpriv->base + 2742f351b2d6SSaeed Bishara HC_SOC_MAIN_IRQ_MASK_OFS; 2743f351b2d6SSaeed Bishara } 2744f351b2d6SSaeed Bishara /* global interrupt mask */ 2745f351b2d6SSaeed Bishara writel(0, hpriv->main_mask_reg_addr); 2746f351b2d6SSaeed Bishara 27474447d351STejun Heo n_hc = mv_get_hc_count(host->ports[0]->flags); 2748c6fd2807SJeff Garzik 27494447d351STejun Heo for (port = 0; port < host->n_ports; port++) 2750c6fd2807SJeff Garzik hpriv->ops->read_preamp(hpriv, port, mmio); 2751c6fd2807SJeff Garzik 2752c6fd2807SJeff Garzik rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 2753c6fd2807SJeff Garzik if (rc) 2754c6fd2807SJeff Garzik goto done; 2755c6fd2807SJeff Garzik 2756c6fd2807SJeff Garzik hpriv->ops->reset_flash(hpriv, mmio); 27577bb3c529SSaeed Bishara hpriv->ops->reset_bus(host, mmio); 2758c6fd2807SJeff Garzik hpriv->ops->enable_leds(hpriv, mmio); 2759c6fd2807SJeff Garzik 27604447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2761ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2762c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2763c6fd2807SJeff Garzik 2764c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2765c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2766c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2767c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2768c6fd2807SJeff Garzik } 2769c6fd2807SJeff Garzik 2770c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port); 2771c6fd2807SJeff Garzik } 2772c6fd2807SJeff Garzik 27734447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2774cbcdd875STejun Heo struct ata_port *ap = host->ports[port]; 2775c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2776cbcdd875STejun Heo 2777cbcdd875STejun Heo mv_port_init(&ap->ioaddr, port_mmio); 2778cbcdd875STejun Heo 27797bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2780f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2781f351b2d6SSaeed Bishara unsigned int offset = port_mmio - mmio; 2782cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio"); 2783cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port"); 2784f351b2d6SSaeed Bishara } 27857bb3c529SSaeed Bishara #endif 2786c6fd2807SJeff Garzik } 2787c6fd2807SJeff Garzik 2788c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 2789c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2790c6fd2807SJeff Garzik 2791c6fd2807SJeff Garzik VPRINTK("HC%i: HC config=0x%08x HC IRQ cause " 2792c6fd2807SJeff Garzik "(before clear)=0x%08x\n", hc, 2793c6fd2807SJeff Garzik readl(hc_mmio + HC_CFG_OFS), 2794c6fd2807SJeff Garzik readl(hc_mmio + HC_IRQ_CAUSE_OFS)); 2795c6fd2807SJeff Garzik 2796c6fd2807SJeff Garzik /* Clear any currently outstanding hc interrupt conditions */ 2797c6fd2807SJeff Garzik writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS); 2798c6fd2807SJeff Garzik } 2799c6fd2807SJeff Garzik 2800f351b2d6SSaeed Bishara if (HAS_PCI(host)) { 2801c6fd2807SJeff Garzik /* Clear any currently outstanding host interrupt conditions */ 280202a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 2803c6fd2807SJeff Garzik 2804c6fd2807SJeff Garzik /* and unmask interrupt generation for host regs */ 280502a121daSMark Lord writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs); 2806ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2807f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS_5, 2808f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2809fb621e2fSJeff Garzik else 2810f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS, 2811f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2812c6fd2807SJeff Garzik 2813c6fd2807SJeff Garzik VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 2814c6fd2807SJeff Garzik "PCI int cause/mask=0x%08x/0x%08x\n", 2815f351b2d6SSaeed Bishara readl(hpriv->main_cause_reg_addr), 2816f351b2d6SSaeed Bishara readl(hpriv->main_mask_reg_addr), 281702a121daSMark Lord readl(mmio + hpriv->irq_cause_ofs), 281802a121daSMark Lord readl(mmio + hpriv->irq_mask_ofs)); 2819f351b2d6SSaeed Bishara } else { 2820f351b2d6SSaeed Bishara writelfl(~HC_MAIN_MASKED_IRQS_SOC, 2821f351b2d6SSaeed Bishara hpriv->main_mask_reg_addr); 2822f351b2d6SSaeed Bishara VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x\n", 2823f351b2d6SSaeed Bishara readl(hpriv->main_cause_reg_addr), 2824f351b2d6SSaeed Bishara readl(hpriv->main_mask_reg_addr)); 2825f351b2d6SSaeed Bishara } 2826c6fd2807SJeff Garzik done: 2827c6fd2807SJeff Garzik return rc; 2828c6fd2807SJeff Garzik } 2829c6fd2807SJeff Garzik 2830fbf14e2fSByron Bradley static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev) 2831fbf14e2fSByron Bradley { 2832fbf14e2fSByron Bradley hpriv->crqb_pool = dmam_pool_create("crqb_q", dev, MV_CRQB_Q_SZ, 2833fbf14e2fSByron Bradley MV_CRQB_Q_SZ, 0); 2834fbf14e2fSByron Bradley if (!hpriv->crqb_pool) 2835fbf14e2fSByron Bradley return -ENOMEM; 2836fbf14e2fSByron Bradley 2837fbf14e2fSByron Bradley hpriv->crpb_pool = dmam_pool_create("crpb_q", dev, MV_CRPB_Q_SZ, 2838fbf14e2fSByron Bradley MV_CRPB_Q_SZ, 0); 2839fbf14e2fSByron Bradley if (!hpriv->crpb_pool) 2840fbf14e2fSByron Bradley return -ENOMEM; 2841fbf14e2fSByron Bradley 2842fbf14e2fSByron Bradley hpriv->sg_tbl_pool = dmam_pool_create("sg_tbl", dev, MV_SG_TBL_SZ, 2843fbf14e2fSByron Bradley MV_SG_TBL_SZ, 0); 2844fbf14e2fSByron Bradley if (!hpriv->sg_tbl_pool) 2845fbf14e2fSByron Bradley return -ENOMEM; 2846fbf14e2fSByron Bradley 2847fbf14e2fSByron Bradley return 0; 2848fbf14e2fSByron Bradley } 2849fbf14e2fSByron Bradley 2850f351b2d6SSaeed Bishara /** 2851f351b2d6SSaeed Bishara * mv_platform_probe - handle a positive probe of an soc Marvell 2852f351b2d6SSaeed Bishara * host 2853f351b2d6SSaeed Bishara * @pdev: platform device found 2854f351b2d6SSaeed Bishara * 2855f351b2d6SSaeed Bishara * LOCKING: 2856f351b2d6SSaeed Bishara * Inherited from caller. 2857f351b2d6SSaeed Bishara */ 2858f351b2d6SSaeed Bishara static int mv_platform_probe(struct platform_device *pdev) 2859f351b2d6SSaeed Bishara { 2860f351b2d6SSaeed Bishara static int printed_version; 2861f351b2d6SSaeed Bishara const struct mv_sata_platform_data *mv_platform_data; 2862f351b2d6SSaeed Bishara const struct ata_port_info *ppi[] = 2863f351b2d6SSaeed Bishara { &mv_port_info[chip_soc], NULL }; 2864f351b2d6SSaeed Bishara struct ata_host *host; 2865f351b2d6SSaeed Bishara struct mv_host_priv *hpriv; 2866f351b2d6SSaeed Bishara struct resource *res; 2867f351b2d6SSaeed Bishara int n_ports, rc; 2868f351b2d6SSaeed Bishara 2869f351b2d6SSaeed Bishara if (!printed_version++) 2870f351b2d6SSaeed Bishara dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2871f351b2d6SSaeed Bishara 2872f351b2d6SSaeed Bishara /* 2873f351b2d6SSaeed Bishara * Simple resource validation .. 2874f351b2d6SSaeed Bishara */ 2875f351b2d6SSaeed Bishara if (unlikely(pdev->num_resources != 2)) { 2876f351b2d6SSaeed Bishara dev_err(&pdev->dev, "invalid number of resources\n"); 2877f351b2d6SSaeed Bishara return -EINVAL; 2878f351b2d6SSaeed Bishara } 2879f351b2d6SSaeed Bishara 2880f351b2d6SSaeed Bishara /* 2881f351b2d6SSaeed Bishara * Get the register base first 2882f351b2d6SSaeed Bishara */ 2883f351b2d6SSaeed Bishara res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2884f351b2d6SSaeed Bishara if (res == NULL) 2885f351b2d6SSaeed Bishara return -EINVAL; 2886f351b2d6SSaeed Bishara 2887f351b2d6SSaeed Bishara /* allocate host */ 2888f351b2d6SSaeed Bishara mv_platform_data = pdev->dev.platform_data; 2889f351b2d6SSaeed Bishara n_ports = mv_platform_data->n_ports; 2890f351b2d6SSaeed Bishara 2891f351b2d6SSaeed Bishara host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 2892f351b2d6SSaeed Bishara hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 2893f351b2d6SSaeed Bishara 2894f351b2d6SSaeed Bishara if (!host || !hpriv) 2895f351b2d6SSaeed Bishara return -ENOMEM; 2896f351b2d6SSaeed Bishara host->private_data = hpriv; 2897f351b2d6SSaeed Bishara hpriv->n_ports = n_ports; 2898f351b2d6SSaeed Bishara 2899f351b2d6SSaeed Bishara host->iomap = NULL; 2900f1cb0ea1SSaeed Bishara hpriv->base = devm_ioremap(&pdev->dev, res->start, 2901f1cb0ea1SSaeed Bishara res->end - res->start + 1); 2902f351b2d6SSaeed Bishara hpriv->base -= MV_SATAHC0_REG_BASE; 2903f351b2d6SSaeed Bishara 2904fbf14e2fSByron Bradley rc = mv_create_dma_pools(hpriv, &pdev->dev); 2905fbf14e2fSByron Bradley if (rc) 2906fbf14e2fSByron Bradley return rc; 2907fbf14e2fSByron Bradley 2908f351b2d6SSaeed Bishara /* initialize adapter */ 2909f351b2d6SSaeed Bishara rc = mv_init_host(host, chip_soc); 2910f351b2d6SSaeed Bishara if (rc) 2911f351b2d6SSaeed Bishara return rc; 2912f351b2d6SSaeed Bishara 2913f351b2d6SSaeed Bishara dev_printk(KERN_INFO, &pdev->dev, 2914f351b2d6SSaeed Bishara "slots %u ports %d\n", (unsigned)MV_MAX_Q_DEPTH, 2915f351b2d6SSaeed Bishara host->n_ports); 2916f351b2d6SSaeed Bishara 2917f351b2d6SSaeed Bishara return ata_host_activate(host, platform_get_irq(pdev, 0), mv_interrupt, 2918f351b2d6SSaeed Bishara IRQF_SHARED, &mv6_sht); 2919f351b2d6SSaeed Bishara } 2920f351b2d6SSaeed Bishara 2921f351b2d6SSaeed Bishara /* 2922f351b2d6SSaeed Bishara * 2923f351b2d6SSaeed Bishara * mv_platform_remove - unplug a platform interface 2924f351b2d6SSaeed Bishara * @pdev: platform device 2925f351b2d6SSaeed Bishara * 2926f351b2d6SSaeed Bishara * A platform bus SATA device has been unplugged. Perform the needed 2927f351b2d6SSaeed Bishara * cleanup. Also called on module unload for any active devices. 2928f351b2d6SSaeed Bishara */ 2929f351b2d6SSaeed Bishara static int __devexit mv_platform_remove(struct platform_device *pdev) 2930f351b2d6SSaeed Bishara { 2931f351b2d6SSaeed Bishara struct device *dev = &pdev->dev; 2932f351b2d6SSaeed Bishara struct ata_host *host = dev_get_drvdata(dev); 2933f351b2d6SSaeed Bishara 2934f351b2d6SSaeed Bishara ata_host_detach(host); 2935f351b2d6SSaeed Bishara return 0; 2936f351b2d6SSaeed Bishara } 2937f351b2d6SSaeed Bishara 2938f351b2d6SSaeed Bishara static struct platform_driver mv_platform_driver = { 2939f351b2d6SSaeed Bishara .probe = mv_platform_probe, 2940f351b2d6SSaeed Bishara .remove = __devexit_p(mv_platform_remove), 2941f351b2d6SSaeed Bishara .driver = { 2942f351b2d6SSaeed Bishara .name = DRV_NAME, 2943f351b2d6SSaeed Bishara .owner = THIS_MODULE, 2944f351b2d6SSaeed Bishara }, 2945f351b2d6SSaeed Bishara }; 2946f351b2d6SSaeed Bishara 2947f351b2d6SSaeed Bishara 29487bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2949f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 2950f351b2d6SSaeed Bishara const struct pci_device_id *ent); 2951f351b2d6SSaeed Bishara 29527bb3c529SSaeed Bishara 29537bb3c529SSaeed Bishara static struct pci_driver mv_pci_driver = { 29547bb3c529SSaeed Bishara .name = DRV_NAME, 29557bb3c529SSaeed Bishara .id_table = mv_pci_tbl, 2956f351b2d6SSaeed Bishara .probe = mv_pci_init_one, 29577bb3c529SSaeed Bishara .remove = ata_pci_remove_one, 29587bb3c529SSaeed Bishara }; 29597bb3c529SSaeed Bishara 29607bb3c529SSaeed Bishara /* 29617bb3c529SSaeed Bishara * module options 29627bb3c529SSaeed Bishara */ 29637bb3c529SSaeed Bishara static int msi; /* Use PCI msi; either zero (off, default) or non-zero */ 29647bb3c529SSaeed Bishara 29657bb3c529SSaeed Bishara 29667bb3c529SSaeed Bishara /* move to PCI layer or libata core? */ 29677bb3c529SSaeed Bishara static int pci_go_64(struct pci_dev *pdev) 29687bb3c529SSaeed Bishara { 29697bb3c529SSaeed Bishara int rc; 29707bb3c529SSaeed Bishara 29717bb3c529SSaeed Bishara if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 29727bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 29737bb3c529SSaeed Bishara if (rc) { 29747bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 29757bb3c529SSaeed Bishara if (rc) { 29767bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 29777bb3c529SSaeed Bishara "64-bit DMA enable failed\n"); 29787bb3c529SSaeed Bishara return rc; 29797bb3c529SSaeed Bishara } 29807bb3c529SSaeed Bishara } 29817bb3c529SSaeed Bishara } else { 29827bb3c529SSaeed Bishara rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 29837bb3c529SSaeed Bishara if (rc) { 29847bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 29857bb3c529SSaeed Bishara "32-bit DMA enable failed\n"); 29867bb3c529SSaeed Bishara return rc; 29877bb3c529SSaeed Bishara } 29887bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 29897bb3c529SSaeed Bishara if (rc) { 29907bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 29917bb3c529SSaeed Bishara "32-bit consistent DMA enable failed\n"); 29927bb3c529SSaeed Bishara return rc; 29937bb3c529SSaeed Bishara } 29947bb3c529SSaeed Bishara } 29957bb3c529SSaeed Bishara 29967bb3c529SSaeed Bishara return rc; 29977bb3c529SSaeed Bishara } 29987bb3c529SSaeed Bishara 2999c6fd2807SJeff Garzik /** 3000c6fd2807SJeff Garzik * mv_print_info - Dump key info to kernel log for perusal. 30014447d351STejun Heo * @host: ATA host to print info about 3002c6fd2807SJeff Garzik * 3003c6fd2807SJeff Garzik * FIXME: complete this. 3004c6fd2807SJeff Garzik * 3005c6fd2807SJeff Garzik * LOCKING: 3006c6fd2807SJeff Garzik * Inherited from caller. 3007c6fd2807SJeff Garzik */ 30084447d351STejun Heo static void mv_print_info(struct ata_host *host) 3009c6fd2807SJeff Garzik { 30104447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 30114447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 301244c10138SAuke Kok u8 scc; 3013c1e4fe71SJeff Garzik const char *scc_s, *gen; 3014c6fd2807SJeff Garzik 3015c6fd2807SJeff Garzik /* Use this to determine the HW stepping of the chip so we know 3016c6fd2807SJeff Garzik * what errata to workaround 3017c6fd2807SJeff Garzik */ 3018c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc); 3019c6fd2807SJeff Garzik if (scc == 0) 3020c6fd2807SJeff Garzik scc_s = "SCSI"; 3021c6fd2807SJeff Garzik else if (scc == 0x01) 3022c6fd2807SJeff Garzik scc_s = "RAID"; 3023c6fd2807SJeff Garzik else 3024c1e4fe71SJeff Garzik scc_s = "?"; 3025c1e4fe71SJeff Garzik 3026c1e4fe71SJeff Garzik if (IS_GEN_I(hpriv)) 3027c1e4fe71SJeff Garzik gen = "I"; 3028c1e4fe71SJeff Garzik else if (IS_GEN_II(hpriv)) 3029c1e4fe71SJeff Garzik gen = "II"; 3030c1e4fe71SJeff Garzik else if (IS_GEN_IIE(hpriv)) 3031c1e4fe71SJeff Garzik gen = "IIE"; 3032c1e4fe71SJeff Garzik else 3033c1e4fe71SJeff Garzik gen = "?"; 3034c6fd2807SJeff Garzik 3035c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, 3036c1e4fe71SJeff Garzik "Gen-%s %u slots %u ports %s mode IRQ via %s\n", 3037c1e4fe71SJeff Garzik gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports, 3038c6fd2807SJeff Garzik scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 3039c6fd2807SJeff Garzik } 3040c6fd2807SJeff Garzik 3041c6fd2807SJeff Garzik /** 3042f351b2d6SSaeed Bishara * mv_pci_init_one - handle a positive probe of a PCI Marvell host 3043c6fd2807SJeff Garzik * @pdev: PCI device found 3044c6fd2807SJeff Garzik * @ent: PCI device ID entry for the matched host 3045c6fd2807SJeff Garzik * 3046c6fd2807SJeff Garzik * LOCKING: 3047c6fd2807SJeff Garzik * Inherited from caller. 3048c6fd2807SJeff Garzik */ 3049f351b2d6SSaeed Bishara static int mv_pci_init_one(struct pci_dev *pdev, 3050f351b2d6SSaeed Bishara const struct pci_device_id *ent) 3051c6fd2807SJeff Garzik { 30522dcb407eSJeff Garzik static int printed_version; 3053c6fd2807SJeff Garzik unsigned int board_idx = (unsigned int)ent->driver_data; 30544447d351STejun Heo const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL }; 30554447d351STejun Heo struct ata_host *host; 30564447d351STejun Heo struct mv_host_priv *hpriv; 30574447d351STejun Heo int n_ports, rc; 3058c6fd2807SJeff Garzik 3059c6fd2807SJeff Garzik if (!printed_version++) 3060c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 3061c6fd2807SJeff Garzik 30624447d351STejun Heo /* allocate host */ 30634447d351STejun Heo n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC; 30644447d351STejun Heo 30654447d351STejun Heo host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 30664447d351STejun Heo hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 30674447d351STejun Heo if (!host || !hpriv) 30684447d351STejun Heo return -ENOMEM; 30694447d351STejun Heo host->private_data = hpriv; 3070f351b2d6SSaeed Bishara hpriv->n_ports = n_ports; 30714447d351STejun Heo 30724447d351STejun Heo /* acquire resources */ 307324dc5f33STejun Heo rc = pcim_enable_device(pdev); 307424dc5f33STejun Heo if (rc) 3075c6fd2807SJeff Garzik return rc; 3076c6fd2807SJeff Garzik 30770d5ff566STejun Heo rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 30780d5ff566STejun Heo if (rc == -EBUSY) 307924dc5f33STejun Heo pcim_pin_device(pdev); 30800d5ff566STejun Heo if (rc) 308124dc5f33STejun Heo return rc; 30824447d351STejun Heo host->iomap = pcim_iomap_table(pdev); 3083f351b2d6SSaeed Bishara hpriv->base = host->iomap[MV_PRIMARY_BAR]; 3084c6fd2807SJeff Garzik 3085d88184fbSJeff Garzik rc = pci_go_64(pdev); 3086d88184fbSJeff Garzik if (rc) 3087d88184fbSJeff Garzik return rc; 3088d88184fbSJeff Garzik 3089da2fa9baSMark Lord rc = mv_create_dma_pools(hpriv, &pdev->dev); 3090da2fa9baSMark Lord if (rc) 3091da2fa9baSMark Lord return rc; 3092da2fa9baSMark Lord 3093c6fd2807SJeff Garzik /* initialize adapter */ 30944447d351STejun Heo rc = mv_init_host(host, board_idx); 309524dc5f33STejun Heo if (rc) 309624dc5f33STejun Heo return rc; 3097c6fd2807SJeff Garzik 3098c6fd2807SJeff Garzik /* Enable interrupts */ 30996a59dcf8STejun Heo if (msi && pci_enable_msi(pdev)) 3100c6fd2807SJeff Garzik pci_intx(pdev, 1); 3101c6fd2807SJeff Garzik 3102c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 31034447d351STejun Heo mv_print_info(host); 3104c6fd2807SJeff Garzik 31054447d351STejun Heo pci_set_master(pdev); 3106ea8b4db9SJeff Garzik pci_try_set_mwi(pdev); 31074447d351STejun Heo return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, 3108c5d3e45aSJeff Garzik IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht); 3109c6fd2807SJeff Garzik } 31107bb3c529SSaeed Bishara #endif 3111c6fd2807SJeff Garzik 3112f351b2d6SSaeed Bishara static int mv_platform_probe(struct platform_device *pdev); 3113f351b2d6SSaeed Bishara static int __devexit mv_platform_remove(struct platform_device *pdev); 3114f351b2d6SSaeed Bishara 3115c6fd2807SJeff Garzik static int __init mv_init(void) 3116c6fd2807SJeff Garzik { 31177bb3c529SSaeed Bishara int rc = -ENODEV; 31187bb3c529SSaeed Bishara #ifdef CONFIG_PCI 31197bb3c529SSaeed Bishara rc = pci_register_driver(&mv_pci_driver); 3120f351b2d6SSaeed Bishara if (rc < 0) 3121f351b2d6SSaeed Bishara return rc; 3122f351b2d6SSaeed Bishara #endif 3123f351b2d6SSaeed Bishara rc = platform_driver_register(&mv_platform_driver); 3124f351b2d6SSaeed Bishara 3125f351b2d6SSaeed Bishara #ifdef CONFIG_PCI 3126f351b2d6SSaeed Bishara if (rc < 0) 3127f351b2d6SSaeed Bishara pci_unregister_driver(&mv_pci_driver); 31287bb3c529SSaeed Bishara #endif 31297bb3c529SSaeed Bishara return rc; 3130c6fd2807SJeff Garzik } 3131c6fd2807SJeff Garzik 3132c6fd2807SJeff Garzik static void __exit mv_exit(void) 3133c6fd2807SJeff Garzik { 31347bb3c529SSaeed Bishara #ifdef CONFIG_PCI 3135c6fd2807SJeff Garzik pci_unregister_driver(&mv_pci_driver); 31367bb3c529SSaeed Bishara #endif 3137f351b2d6SSaeed Bishara platform_driver_unregister(&mv_platform_driver); 3138c6fd2807SJeff Garzik } 3139c6fd2807SJeff Garzik 3140c6fd2807SJeff Garzik MODULE_AUTHOR("Brett Russ"); 3141c6fd2807SJeff Garzik MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers"); 3142c6fd2807SJeff Garzik MODULE_LICENSE("GPL"); 3143c6fd2807SJeff Garzik MODULE_DEVICE_TABLE(pci, mv_pci_tbl); 3144c6fd2807SJeff Garzik MODULE_VERSION(DRV_VERSION); 31452e7e1214SMartin Michlmayr MODULE_ALIAS("platform:sata_mv"); 3146c6fd2807SJeff Garzik 31477bb3c529SSaeed Bishara #ifdef CONFIG_PCI 3148c6fd2807SJeff Garzik module_param(msi, int, 0444); 3149c6fd2807SJeff Garzik MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)"); 31507bb3c529SSaeed Bishara #endif 3151c6fd2807SJeff Garzik 3152c6fd2807SJeff Garzik module_init(mv_init); 3153c6fd2807SJeff Garzik module_exit(mv_exit); 3154