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