blob: 6dc2a612ccbdf9170878c4b3aa2294584b760715 [file] [log] [blame]
Brett Russ20f733e2005-09-01 18:26:17 -04001/*
2 * sata_mv.c - Marvell SATA support
3 *
Jeff Garzik8b260242005-11-12 12:32:50 -05004 * Copyright 2005: EMC Corporation, all rights reserved.
Brett Russ20f733e2005-09-01 18:26:17 -04005 *
6 * Please ALWAYS copy linux-ide@vger.kernel.org on emails.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/pci.h>
26#include <linux/init.h>
27#include <linux/blkdev.h>
28#include <linux/delay.h>
29#include <linux/interrupt.h>
30#include <linux/sched.h>
31#include <linux/dma-mapping.h>
Jeff Garzika9524a72005-10-30 14:39:11 -050032#include <linux/device.h>
Brett Russ20f733e2005-09-01 18:26:17 -040033#include <scsi/scsi_host.h>
Jeff Garzik193515d2005-11-07 00:59:37 -050034#include <scsi/scsi_cmnd.h>
Brett Russ20f733e2005-09-01 18:26:17 -040035#include <linux/libata.h>
36#include <asm/io.h>
37
38#define DRV_NAME "sata_mv"
Brett Russ7e6c1202005-10-20 08:39:43 -040039#define DRV_VERSION "0.25"
Brett Russ20f733e2005-09-01 18:26:17 -040040
41enum {
42 /* BAR's are enumerated in terms of pci_resource_start() terms */
43 MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */
44 MV_IO_BAR = 2, /* offset 0x18: IO space */
45 MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */
46
47 MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
48 MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
49
50 MV_PCI_REG_BASE = 0,
51 MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */
52 MV_SATAHC0_REG_BASE = 0x20000,
Jeff Garzik522479f2005-11-12 22:14:02 -050053 MV_FLASH_CTL = 0x1046c,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -050054 MV_GPIO_PORT_CTL = 0x104f0,
55 MV_RESET_CFG = 0x180d8,
Brett Russ20f733e2005-09-01 18:26:17 -040056
57 MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ,
58 MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ,
59 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
60 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
61
Brett Russ31961942005-09-30 01:36:00 -040062 MV_USE_Q_DEPTH = ATA_DEF_QUEUE,
Brett Russ20f733e2005-09-01 18:26:17 -040063
Brett Russ31961942005-09-30 01:36:00 -040064 MV_MAX_Q_DEPTH = 32,
65 MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
66
67 /* CRQB needs alignment on a 1KB boundary. Size == 1KB
68 * CRPB needs alignment on a 256B boundary. Size == 256B
69 * SG count of 176 leads to MV_PORT_PRIV_DMA_SZ == 4KB
70 * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B
71 */
72 MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH),
73 MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH),
74 MV_MAX_SG_CT = 176,
75 MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
76 MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ),
77
Brett Russ20f733e2005-09-01 18:26:17 -040078 MV_PORTS_PER_HC = 4,
79 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
80 MV_PORT_HC_SHIFT = 2,
Brett Russ31961942005-09-30 01:36:00 -040081 /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */
Brett Russ20f733e2005-09-01 18:26:17 -040082 MV_PORT_MASK = 3,
83
84 /* Host Flags */
85 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
86 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
Brett Russ31961942005-09-30 01:36:00 -040087 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
Jeff Garzikf58f8be2005-10-09 09:44:07 -040088 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
89 ATA_FLAG_PIO_POLLING),
Jeff Garzik47c2b672005-11-12 21:13:17 -050090 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
Brett Russ20f733e2005-09-01 18:26:17 -040091
Brett Russ31961942005-09-30 01:36:00 -040092 CRQB_FLAG_READ = (1 << 0),
93 CRQB_TAG_SHIFT = 1,
94 CRQB_CMD_ADDR_SHIFT = 8,
95 CRQB_CMD_CS = (0x2 << 11),
96 CRQB_CMD_LAST = (1 << 15),
97
98 CRPB_FLAG_STATUS_SHIFT = 8,
99
100 EPRD_FLAG_END_OF_TBL = (1 << 31),
101
Brett Russ20f733e2005-09-01 18:26:17 -0400102 /* PCI interface registers */
103
Brett Russ31961942005-09-30 01:36:00 -0400104 PCI_COMMAND_OFS = 0xc00,
105
Brett Russ20f733e2005-09-01 18:26:17 -0400106 PCI_MAIN_CMD_STS_OFS = 0xd30,
107 STOP_PCI_MASTER = (1 << 2),
108 PCI_MASTER_EMPTY = (1 << 3),
109 GLOB_SFT_RST = (1 << 4),
110
Jeff Garzik522479f2005-11-12 22:14:02 -0500111 MV_PCI_MODE = 0xd00,
112 MV_PCI_EXP_ROM_BAR_CTL = 0xd2c,
113 MV_PCI_DISC_TIMER = 0xd04,
114 MV_PCI_MSI_TRIGGER = 0xc38,
115 MV_PCI_SERR_MASK = 0xc28,
116 MV_PCI_XBAR_TMOUT = 0x1d04,
117 MV_PCI_ERR_LOW_ADDRESS = 0x1d40,
118 MV_PCI_ERR_HIGH_ADDRESS = 0x1d44,
119 MV_PCI_ERR_ATTRIBUTE = 0x1d48,
120 MV_PCI_ERR_COMMAND = 0x1d50,
121
122 PCI_IRQ_CAUSE_OFS = 0x1d58,
123 PCI_IRQ_MASK_OFS = 0x1d5c,
Brett Russ20f733e2005-09-01 18:26:17 -0400124 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
125
126 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
127 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
128 PORT0_ERR = (1 << 0), /* shift by port # */
129 PORT0_DONE = (1 << 1), /* shift by port # */
130 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
131 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
132 PCI_ERR = (1 << 18),
133 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
134 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
135 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
136 GPIO_INT = (1 << 22),
137 SELF_INT = (1 << 23),
138 TWSI_INT = (1 << 24),
139 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
Jeff Garzik8b260242005-11-12 12:32:50 -0500140 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
Brett Russ20f733e2005-09-01 18:26:17 -0400141 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
142 HC_MAIN_RSVD),
143
144 /* SATAHC registers */
145 HC_CFG_OFS = 0,
146
147 HC_IRQ_CAUSE_OFS = 0x14,
Brett Russ31961942005-09-30 01:36:00 -0400148 CRPB_DMA_DONE = (1 << 0), /* shift by port # */
Brett Russ20f733e2005-09-01 18:26:17 -0400149 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
150 DEV_IRQ = (1 << 8), /* shift by port # */
151
152 /* Shadow block registers */
Brett Russ31961942005-09-30 01:36:00 -0400153 SHD_BLK_OFS = 0x100,
154 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
Brett Russ20f733e2005-09-01 18:26:17 -0400155
156 /* SATA registers */
157 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
158 SATA_ACTIVE_OFS = 0x350,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500159 PHY_MODE3 = 0x310,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500160 PHY_MODE4 = 0x314,
161 PHY_MODE2 = 0x330,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500162 MV5_PHY_MODE = 0x74,
163 MV5_LT_MODE = 0x30,
164 MV5_PHY_CTL = 0x0C,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500165 SATA_INTERFACE_CTL = 0x050,
166
167 MV_M2_PREAMP_MASK = 0x7e0,
Brett Russ20f733e2005-09-01 18:26:17 -0400168
169 /* Port registers */
170 EDMA_CFG_OFS = 0,
Brett Russ31961942005-09-30 01:36:00 -0400171 EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */
172 EDMA_CFG_NCQ = (1 << 5),
173 EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
174 EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
175 EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
Brett Russ20f733e2005-09-01 18:26:17 -0400176
177 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
178 EDMA_ERR_IRQ_MASK_OFS = 0xc,
179 EDMA_ERR_D_PAR = (1 << 0),
180 EDMA_ERR_PRD_PAR = (1 << 1),
181 EDMA_ERR_DEV = (1 << 2),
182 EDMA_ERR_DEV_DCON = (1 << 3),
183 EDMA_ERR_DEV_CON = (1 << 4),
184 EDMA_ERR_SERR = (1 << 5),
185 EDMA_ERR_SELF_DIS = (1 << 7),
186 EDMA_ERR_BIST_ASYNC = (1 << 8),
187 EDMA_ERR_CRBQ_PAR = (1 << 9),
188 EDMA_ERR_CRPB_PAR = (1 << 10),
189 EDMA_ERR_INTRL_PAR = (1 << 11),
190 EDMA_ERR_IORDY = (1 << 12),
191 EDMA_ERR_LNK_CTRL_RX = (0xf << 13),
192 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
193 EDMA_ERR_LNK_DATA_RX = (0xf << 17),
194 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21),
195 EDMA_ERR_LNK_DATA_TX = (0x1f << 26),
196 EDMA_ERR_TRANS_PROTO = (1 << 31),
Jeff Garzik8b260242005-11-12 12:32:50 -0500197 EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
Brett Russ20f733e2005-09-01 18:26:17 -0400198 EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR |
199 EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR |
Jeff Garzik8b260242005-11-12 12:32:50 -0500200 EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 |
Brett Russ20f733e2005-09-01 18:26:17 -0400201 EDMA_ERR_LNK_DATA_RX |
Jeff Garzik8b260242005-11-12 12:32:50 -0500202 EDMA_ERR_LNK_DATA_TX |
Brett Russ20f733e2005-09-01 18:26:17 -0400203 EDMA_ERR_TRANS_PROTO),
204
Brett Russ31961942005-09-30 01:36:00 -0400205 EDMA_REQ_Q_BASE_HI_OFS = 0x10,
206 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400207
208 EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
209 EDMA_REQ_Q_PTR_SHIFT = 5,
210
211 EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
212 EDMA_RSP_Q_IN_PTR_OFS = 0x20,
213 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400214 EDMA_RSP_Q_PTR_SHIFT = 3,
215
Brett Russ20f733e2005-09-01 18:26:17 -0400216 EDMA_CMD_OFS = 0x28,
217 EDMA_EN = (1 << 0),
218 EDMA_DS = (1 << 1),
219 ATA_RST = (1 << 2),
220
Jeff Garzikc9d39132005-11-13 17:47:51 -0500221 EDMA_IORDY_TMOUT = 0x34,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500222 EDMA_ARB_CFG = 0x38,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500223
Brett Russ31961942005-09-30 01:36:00 -0400224 /* Host private flags (hp_flags) */
225 MV_HP_FLAG_MSI = (1 << 0),
Jeff Garzik47c2b672005-11-12 21:13:17 -0500226 MV_HP_ERRATA_50XXB0 = (1 << 1),
227 MV_HP_ERRATA_50XXB2 = (1 << 2),
228 MV_HP_ERRATA_60X1B2 = (1 << 3),
229 MV_HP_ERRATA_60X1C0 = (1 << 4),
230 MV_HP_50XX = (1 << 5),
Brett Russ20f733e2005-09-01 18:26:17 -0400231
Brett Russ31961942005-09-30 01:36:00 -0400232 /* Port private flags (pp_flags) */
233 MV_PP_FLAG_EDMA_EN = (1 << 0),
234 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1),
235};
236
Jeff Garzikc9d39132005-11-13 17:47:51 -0500237#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500238#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0)
239
Jeff Garzik095fec82005-11-12 09:50:49 -0500240enum {
241 /* Our DMA boundary is determined by an ePRD being unable to handle
242 * anything larger than 64KB
243 */
244 MV_DMA_BOUNDARY = 0xffffU,
245
246 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
247
248 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
249};
250
Jeff Garzik522479f2005-11-12 22:14:02 -0500251enum chip_type {
252 chip_504x,
253 chip_508x,
254 chip_5080,
255 chip_604x,
256 chip_608x,
257};
258
Brett Russ31961942005-09-30 01:36:00 -0400259/* Command ReQuest Block: 32B */
260struct mv_crqb {
261 u32 sg_addr;
262 u32 sg_addr_hi;
263 u16 ctrl_flags;
264 u16 ata_cmd[11];
265};
266
267/* Command ResPonse Block: 8B */
268struct mv_crpb {
269 u16 id;
270 u16 flags;
271 u32 tmstmp;
272};
273
274/* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
275struct mv_sg {
276 u32 addr;
277 u32 flags_size;
278 u32 addr_hi;
279 u32 reserved;
Brett Russ20f733e2005-09-01 18:26:17 -0400280};
281
282struct mv_port_priv {
Brett Russ31961942005-09-30 01:36:00 -0400283 struct mv_crqb *crqb;
284 dma_addr_t crqb_dma;
285 struct mv_crpb *crpb;
286 dma_addr_t crpb_dma;
287 struct mv_sg *sg_tbl;
288 dma_addr_t sg_tbl_dma;
Brett Russ20f733e2005-09-01 18:26:17 -0400289
Brett Russ31961942005-09-30 01:36:00 -0400290 unsigned req_producer; /* cp of req_in_ptr */
291 unsigned rsp_consumer; /* cp of rsp_out_ptr */
292 u32 pp_flags;
Brett Russ20f733e2005-09-01 18:26:17 -0400293};
294
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500295struct mv_port_signal {
296 u32 amps;
297 u32 pre;
298};
299
Jeff Garzik47c2b672005-11-12 21:13:17 -0500300struct mv_host_priv;
301struct mv_hw_ops {
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500302 void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
303 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500304 void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio);
305 void (*read_preamp)(struct mv_host_priv *hpriv, int idx,
306 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500307 int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio,
308 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500309 void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio);
310 void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500311};
312
Brett Russ20f733e2005-09-01 18:26:17 -0400313struct mv_host_priv {
Brett Russ31961942005-09-30 01:36:00 -0400314 u32 hp_flags;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500315 struct mv_port_signal signal[8];
Jeff Garzik47c2b672005-11-12 21:13:17 -0500316 const struct mv_hw_ops *ops;
Brett Russ20f733e2005-09-01 18:26:17 -0400317};
318
319static void mv_irq_clear(struct ata_port *ap);
320static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
321static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500322static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
323static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Brett Russ20f733e2005-09-01 18:26:17 -0400324static void mv_phy_reset(struct ata_port *ap);
Jeff Garzik22374672005-11-17 10:59:48 -0500325static void __mv_phy_reset(struct ata_port *ap, int can_sleep);
Brett Russ31961942005-09-30 01:36:00 -0400326static void mv_host_stop(struct ata_host_set *host_set);
327static int mv_port_start(struct ata_port *ap);
328static void mv_port_stop(struct ata_port *ap);
329static void mv_qc_prep(struct ata_queued_cmd *qc);
330static int mv_qc_issue(struct ata_queued_cmd *qc);
Brett Russ20f733e2005-09-01 18:26:17 -0400331static irqreturn_t mv_interrupt(int irq, void *dev_instance,
332 struct pt_regs *regs);
Brett Russ31961942005-09-30 01:36:00 -0400333static void mv_eng_timeout(struct ata_port *ap);
Brett Russ20f733e2005-09-01 18:26:17 -0400334static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
335
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500336static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
337 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500338static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
339static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
340 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500341static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
342 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500343static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
344static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500345
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500346static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
347 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500348static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
349static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
350 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500351static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
352 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500353static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
354static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500355static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
356 unsigned int port_no);
357static void mv_stop_and_reset(struct ata_port *ap);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500358
Jeff Garzik193515d2005-11-07 00:59:37 -0500359static struct scsi_host_template mv_sht = {
Brett Russ20f733e2005-09-01 18:26:17 -0400360 .module = THIS_MODULE,
361 .name = DRV_NAME,
362 .ioctl = ata_scsi_ioctl,
363 .queuecommand = ata_scsi_queuecmd,
364 .eh_strategy_handler = ata_scsi_error,
Brett Russ31961942005-09-30 01:36:00 -0400365 .can_queue = MV_USE_Q_DEPTH,
Brett Russ20f733e2005-09-01 18:26:17 -0400366 .this_id = ATA_SHT_THIS_ID,
Jeff Garzik22374672005-11-17 10:59:48 -0500367 .sg_tablesize = MV_MAX_SG_CT / 2,
Brett Russ20f733e2005-09-01 18:26:17 -0400368 .max_sectors = ATA_MAX_SECTORS,
369 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
370 .emulated = ATA_SHT_EMULATED,
Brett Russ31961942005-09-30 01:36:00 -0400371 .use_clustering = ATA_SHT_USE_CLUSTERING,
Brett Russ20f733e2005-09-01 18:26:17 -0400372 .proc_name = DRV_NAME,
373 .dma_boundary = MV_DMA_BOUNDARY,
374 .slave_configure = ata_scsi_slave_config,
375 .bios_param = ata_std_bios_param,
376 .ordered_flush = 1,
377};
378
Jeff Garzikc9d39132005-11-13 17:47:51 -0500379static const struct ata_port_operations mv5_ops = {
380 .port_disable = ata_port_disable,
381
382 .tf_load = ata_tf_load,
383 .tf_read = ata_tf_read,
384 .check_status = ata_check_status,
385 .exec_command = ata_exec_command,
386 .dev_select = ata_std_dev_select,
387
388 .phy_reset = mv_phy_reset,
389
390 .qc_prep = mv_qc_prep,
391 .qc_issue = mv_qc_issue,
392
393 .eng_timeout = mv_eng_timeout,
394
395 .irq_handler = mv_interrupt,
396 .irq_clear = mv_irq_clear,
397
398 .scr_read = mv5_scr_read,
399 .scr_write = mv5_scr_write,
400
401 .port_start = mv_port_start,
402 .port_stop = mv_port_stop,
403 .host_stop = mv_host_stop,
404};
405
406static const struct ata_port_operations mv6_ops = {
Brett Russ20f733e2005-09-01 18:26:17 -0400407 .port_disable = ata_port_disable,
408
409 .tf_load = ata_tf_load,
410 .tf_read = ata_tf_read,
411 .check_status = ata_check_status,
412 .exec_command = ata_exec_command,
413 .dev_select = ata_std_dev_select,
414
415 .phy_reset = mv_phy_reset,
416
Brett Russ31961942005-09-30 01:36:00 -0400417 .qc_prep = mv_qc_prep,
418 .qc_issue = mv_qc_issue,
Brett Russ20f733e2005-09-01 18:26:17 -0400419
Brett Russ31961942005-09-30 01:36:00 -0400420 .eng_timeout = mv_eng_timeout,
Brett Russ20f733e2005-09-01 18:26:17 -0400421
422 .irq_handler = mv_interrupt,
423 .irq_clear = mv_irq_clear,
424
425 .scr_read = mv_scr_read,
426 .scr_write = mv_scr_write,
427
Brett Russ31961942005-09-30 01:36:00 -0400428 .port_start = mv_port_start,
429 .port_stop = mv_port_stop,
430 .host_stop = mv_host_stop,
Brett Russ20f733e2005-09-01 18:26:17 -0400431};
432
433static struct ata_port_info mv_port_info[] = {
434 { /* chip_504x */
435 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400436 .host_flags = MV_COMMON_FLAGS,
437 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500438 .udma_mask = 0x7f, /* udma0-6 */
439 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400440 },
441 { /* chip_508x */
442 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400443 .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
444 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500445 .udma_mask = 0x7f, /* udma0-6 */
446 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400447 },
Jeff Garzik47c2b672005-11-12 21:13:17 -0500448 { /* chip_5080 */
449 .sht = &mv_sht,
450 .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
451 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500452 .udma_mask = 0x7f, /* udma0-6 */
453 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400454 },
455 { /* chip_604x */
456 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400457 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
458 .pio_mask = 0x1f, /* pio0-4 */
459 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500460 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400461 },
462 { /* chip_608x */
463 .sht = &mv_sht,
Jeff Garzik8b260242005-11-12 12:32:50 -0500464 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
Brett Russ31961942005-09-30 01:36:00 -0400465 MV_FLAG_DUAL_HC),
466 .pio_mask = 0x1f, /* pio0-4 */
467 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500468 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400469 },
470};
471
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500472static const struct pci_device_id mv_pci_tbl[] = {
Brett Russ20f733e2005-09-01 18:26:17 -0400473 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5040), 0, 0, chip_504x},
474 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5041), 0, 0, chip_504x},
Jeff Garzik47c2b672005-11-12 21:13:17 -0500475 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5080), 0, 0, chip_5080},
Brett Russ20f733e2005-09-01 18:26:17 -0400476 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5081), 0, 0, chip_508x},
477
478 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x},
479 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6041), 0, 0, chip_604x},
480 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6080), 0, 0, chip_608x},
481 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6081), 0, 0, chip_608x},
Jeff Garzik29179532005-11-11 08:08:03 -0500482
483 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x0241), 0, 0, chip_604x},
Brett Russ20f733e2005-09-01 18:26:17 -0400484 {} /* terminate list */
485};
486
487static struct pci_driver mv_pci_driver = {
488 .name = DRV_NAME,
489 .id_table = mv_pci_tbl,
490 .probe = mv_init_one,
491 .remove = ata_pci_remove_one,
492};
493
Jeff Garzik47c2b672005-11-12 21:13:17 -0500494static const struct mv_hw_ops mv5xxx_ops = {
495 .phy_errata = mv5_phy_errata,
496 .enable_leds = mv5_enable_leds,
497 .read_preamp = mv5_read_preamp,
498 .reset_hc = mv5_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500499 .reset_flash = mv5_reset_flash,
500 .reset_bus = mv5_reset_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500501};
502
503static const struct mv_hw_ops mv6xxx_ops = {
504 .phy_errata = mv6_phy_errata,
505 .enable_leds = mv6_enable_leds,
506 .read_preamp = mv6_read_preamp,
507 .reset_hc = mv6_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500508 .reset_flash = mv6_reset_flash,
509 .reset_bus = mv_reset_pci_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500510};
511
Brett Russ20f733e2005-09-01 18:26:17 -0400512/*
513 * Functions
514 */
515
516static inline void writelfl(unsigned long data, void __iomem *addr)
517{
518 writel(data, addr);
519 (void) readl(addr); /* flush to avoid PCI posted write */
520}
521
Brett Russ20f733e2005-09-01 18:26:17 -0400522static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
523{
524 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
525}
526
Jeff Garzikc9d39132005-11-13 17:47:51 -0500527static inline unsigned int mv_hc_from_port(unsigned int port)
528{
529 return port >> MV_PORT_HC_SHIFT;
530}
531
532static inline unsigned int mv_hardport_from_port(unsigned int port)
533{
534 return port & MV_PORT_MASK;
535}
536
537static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
538 unsigned int port)
539{
540 return mv_hc_base(base, mv_hc_from_port(port));
541}
542
Brett Russ20f733e2005-09-01 18:26:17 -0400543static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
544{
Jeff Garzikc9d39132005-11-13 17:47:51 -0500545 return mv_hc_base_from_port(base, port) +
Jeff Garzik8b260242005-11-12 12:32:50 -0500546 MV_SATAHC_ARBTR_REG_SZ +
Jeff Garzikc9d39132005-11-13 17:47:51 -0500547 (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
Brett Russ20f733e2005-09-01 18:26:17 -0400548}
549
550static inline void __iomem *mv_ap_base(struct ata_port *ap)
551{
552 return mv_port_base(ap->host_set->mmio_base, ap->port_no);
553}
554
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500555static inline int mv_get_hc_count(unsigned long host_flags)
Brett Russ20f733e2005-09-01 18:26:17 -0400556{
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500557 return ((host_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
Brett Russ20f733e2005-09-01 18:26:17 -0400558}
559
560static void mv_irq_clear(struct ata_port *ap)
561{
562}
563
Brett Russ05b308e2005-10-05 17:08:53 -0400564/**
565 * mv_start_dma - Enable eDMA engine
566 * @base: port base address
567 * @pp: port private data
568 *
569 * Verify the local cache of the eDMA state is accurate with an
570 * assert.
571 *
572 * LOCKING:
573 * Inherited from caller.
574 */
Brett Russafb0edd2005-10-05 17:08:42 -0400575static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
Brett Russ31961942005-09-30 01:36:00 -0400576{
Brett Russafb0edd2005-10-05 17:08:42 -0400577 if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) {
578 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
579 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
580 }
581 assert(EDMA_EN & readl(base + EDMA_CMD_OFS));
Brett Russ31961942005-09-30 01:36:00 -0400582}
583
Brett Russ05b308e2005-10-05 17:08:53 -0400584/**
585 * mv_stop_dma - Disable eDMA engine
586 * @ap: ATA channel to manipulate
587 *
588 * Verify the local cache of the eDMA state is accurate with an
589 * assert.
590 *
591 * LOCKING:
592 * Inherited from caller.
593 */
Brett Russ31961942005-09-30 01:36:00 -0400594static void mv_stop_dma(struct ata_port *ap)
595{
596 void __iomem *port_mmio = mv_ap_base(ap);
597 struct mv_port_priv *pp = ap->private_data;
Brett Russ31961942005-09-30 01:36:00 -0400598 u32 reg;
599 int i;
600
Brett Russafb0edd2005-10-05 17:08:42 -0400601 if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) {
602 /* Disable EDMA if active. The disable bit auto clears.
Brett Russ31961942005-09-30 01:36:00 -0400603 */
Brett Russ31961942005-09-30 01:36:00 -0400604 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
605 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
Brett Russafb0edd2005-10-05 17:08:42 -0400606 } else {
607 assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)));
608 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500609
Brett Russ31961942005-09-30 01:36:00 -0400610 /* now properly wait for the eDMA to stop */
611 for (i = 1000; i > 0; i--) {
612 reg = readl(port_mmio + EDMA_CMD_OFS);
613 if (!(EDMA_EN & reg)) {
614 break;
615 }
616 udelay(100);
617 }
618
Brett Russ31961942005-09-30 01:36:00 -0400619 if (EDMA_EN & reg) {
620 printk(KERN_ERR "ata%u: Unable to stop eDMA\n", ap->id);
Brett Russafb0edd2005-10-05 17:08:42 -0400621 /* FIXME: Consider doing a reset here to recover */
Brett Russ31961942005-09-30 01:36:00 -0400622 }
623}
624
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400625#ifdef ATA_DEBUG
Brett Russ31961942005-09-30 01:36:00 -0400626static void mv_dump_mem(void __iomem *start, unsigned bytes)
627{
Brett Russ31961942005-09-30 01:36:00 -0400628 int b, w;
629 for (b = 0; b < bytes; ) {
630 DPRINTK("%p: ", start + b);
631 for (w = 0; b < bytes && w < 4; w++) {
632 printk("%08x ",readl(start + b));
633 b += sizeof(u32);
634 }
635 printk("\n");
636 }
Brett Russ31961942005-09-30 01:36:00 -0400637}
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400638#endif
639
Brett Russ31961942005-09-30 01:36:00 -0400640static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
641{
642#ifdef ATA_DEBUG
643 int b, w;
644 u32 dw;
645 for (b = 0; b < bytes; ) {
646 DPRINTK("%02x: ", b);
647 for (w = 0; b < bytes && w < 4; w++) {
648 (void) pci_read_config_dword(pdev,b,&dw);
649 printk("%08x ",dw);
650 b += sizeof(u32);
651 }
652 printk("\n");
653 }
654#endif
655}
656static void mv_dump_all_regs(void __iomem *mmio_base, int port,
657 struct pci_dev *pdev)
658{
659#ifdef ATA_DEBUG
Jeff Garzik8b260242005-11-12 12:32:50 -0500660 void __iomem *hc_base = mv_hc_base(mmio_base,
Brett Russ31961942005-09-30 01:36:00 -0400661 port >> MV_PORT_HC_SHIFT);
662 void __iomem *port_base;
663 int start_port, num_ports, p, start_hc, num_hcs, hc;
664
665 if (0 > port) {
666 start_hc = start_port = 0;
667 num_ports = 8; /* shld be benign for 4 port devs */
668 num_hcs = 2;
669 } else {
670 start_hc = port >> MV_PORT_HC_SHIFT;
671 start_port = port;
672 num_ports = num_hcs = 1;
673 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500674 DPRINTK("All registers for port(s) %u-%u:\n", start_port,
Brett Russ31961942005-09-30 01:36:00 -0400675 num_ports > 1 ? num_ports - 1 : start_port);
676
677 if (NULL != pdev) {
678 DPRINTK("PCI config space regs:\n");
679 mv_dump_pci_cfg(pdev, 0x68);
680 }
681 DPRINTK("PCI regs:\n");
682 mv_dump_mem(mmio_base+0xc00, 0x3c);
683 mv_dump_mem(mmio_base+0xd00, 0x34);
684 mv_dump_mem(mmio_base+0xf00, 0x4);
685 mv_dump_mem(mmio_base+0x1d00, 0x6c);
686 for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
687 hc_base = mv_hc_base(mmio_base, port >> MV_PORT_HC_SHIFT);
688 DPRINTK("HC regs (HC %i):\n", hc);
689 mv_dump_mem(hc_base, 0x1c);
690 }
691 for (p = start_port; p < start_port + num_ports; p++) {
692 port_base = mv_port_base(mmio_base, p);
693 DPRINTK("EDMA regs (port %i):\n",p);
694 mv_dump_mem(port_base, 0x54);
695 DPRINTK("SATA regs (port %i):\n",p);
696 mv_dump_mem(port_base+0x300, 0x60);
697 }
698#endif
699}
700
Brett Russ20f733e2005-09-01 18:26:17 -0400701static unsigned int mv_scr_offset(unsigned int sc_reg_in)
702{
703 unsigned int ofs;
704
705 switch (sc_reg_in) {
706 case SCR_STATUS:
707 case SCR_CONTROL:
708 case SCR_ERROR:
709 ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
710 break;
711 case SCR_ACTIVE:
712 ofs = SATA_ACTIVE_OFS; /* active is not with the others */
713 break;
714 default:
715 ofs = 0xffffffffU;
716 break;
717 }
718 return ofs;
719}
720
721static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
722{
723 unsigned int ofs = mv_scr_offset(sc_reg_in);
724
725 if (0xffffffffU != ofs) {
726 return readl(mv_ap_base(ap) + ofs);
727 } else {
728 return (u32) ofs;
729 }
730}
731
732static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
733{
734 unsigned int ofs = mv_scr_offset(sc_reg_in);
735
736 if (0xffffffffU != ofs) {
737 writelfl(val, mv_ap_base(ap) + ofs);
738 }
739}
740
Brett Russ05b308e2005-10-05 17:08:53 -0400741/**
Brett Russ05b308e2005-10-05 17:08:53 -0400742 * mv_host_stop - Host specific cleanup/stop routine.
743 * @host_set: host data structure
744 *
745 * Disable ints, cleanup host memory, call general purpose
746 * host_stop.
747 *
748 * LOCKING:
749 * Inherited from caller.
750 */
Brett Russ31961942005-09-30 01:36:00 -0400751static void mv_host_stop(struct ata_host_set *host_set)
752{
753 struct mv_host_priv *hpriv = host_set->private_data;
754 struct pci_dev *pdev = to_pci_dev(host_set->dev);
755
756 if (hpriv->hp_flags & MV_HP_FLAG_MSI) {
757 pci_disable_msi(pdev);
758 } else {
759 pci_intx(pdev, 0);
760 }
761 kfree(hpriv);
762 ata_host_stop(host_set);
763}
764
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500765static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev)
766{
767 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma);
768}
769
Brett Russ05b308e2005-10-05 17:08:53 -0400770/**
771 * mv_port_start - Port specific init/start routine.
772 * @ap: ATA channel to manipulate
773 *
774 * Allocate and point to DMA memory, init port private memory,
775 * zero indices.
776 *
777 * LOCKING:
778 * Inherited from caller.
779 */
Brett Russ31961942005-09-30 01:36:00 -0400780static int mv_port_start(struct ata_port *ap)
781{
782 struct device *dev = ap->host_set->dev;
783 struct mv_port_priv *pp;
784 void __iomem *port_mmio = mv_ap_base(ap);
785 void *mem;
786 dma_addr_t mem_dma;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500787 int rc = -ENOMEM;
Brett Russ31961942005-09-30 01:36:00 -0400788
789 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500790 if (!pp)
791 goto err_out;
Brett Russ31961942005-09-30 01:36:00 -0400792 memset(pp, 0, sizeof(*pp));
793
Jeff Garzik8b260242005-11-12 12:32:50 -0500794 mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
Brett Russ31961942005-09-30 01:36:00 -0400795 GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500796 if (!mem)
797 goto err_out_pp;
Brett Russ31961942005-09-30 01:36:00 -0400798 memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
799
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500800 rc = ata_pad_alloc(ap, dev);
801 if (rc)
802 goto err_out_priv;
803
Jeff Garzik8b260242005-11-12 12:32:50 -0500804 /* First item in chunk of DMA memory:
Brett Russ31961942005-09-30 01:36:00 -0400805 * 32-slot command request table (CRQB), 32 bytes each in size
806 */
807 pp->crqb = mem;
808 pp->crqb_dma = mem_dma;
809 mem += MV_CRQB_Q_SZ;
810 mem_dma += MV_CRQB_Q_SZ;
811
Jeff Garzik8b260242005-11-12 12:32:50 -0500812 /* Second item:
Brett Russ31961942005-09-30 01:36:00 -0400813 * 32-slot command response table (CRPB), 8 bytes each in size
814 */
815 pp->crpb = mem;
816 pp->crpb_dma = mem_dma;
817 mem += MV_CRPB_Q_SZ;
818 mem_dma += MV_CRPB_Q_SZ;
819
820 /* Third item:
821 * Table of scatter-gather descriptors (ePRD), 16 bytes each
822 */
823 pp->sg_tbl = mem;
824 pp->sg_tbl_dma = mem_dma;
825
Jeff Garzik8b260242005-11-12 12:32:50 -0500826 writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT |
Brett Russ31961942005-09-30 01:36:00 -0400827 EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS);
828
829 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
Jeff Garzik8b260242005-11-12 12:32:50 -0500830 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400831 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
832
833 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
834 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
835
836 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
Jeff Garzik8b260242005-11-12 12:32:50 -0500837 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400838 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
839
840 pp->req_producer = pp->rsp_consumer = 0;
841
842 /* Don't turn on EDMA here...do it before DMA commands only. Else
843 * we'll be unable to send non-data, PIO, etc due to restricted access
844 * to shadow regs.
845 */
846 ap->private_data = pp;
847 return 0;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500848
849err_out_priv:
850 mv_priv_free(pp, dev);
851err_out_pp:
852 kfree(pp);
853err_out:
854 return rc;
Brett Russ31961942005-09-30 01:36:00 -0400855}
856
Brett Russ05b308e2005-10-05 17:08:53 -0400857/**
858 * mv_port_stop - Port specific cleanup/stop routine.
859 * @ap: ATA channel to manipulate
860 *
861 * Stop DMA, cleanup port memory.
862 *
863 * LOCKING:
864 * This routine uses the host_set lock to protect the DMA stop.
865 */
Brett Russ31961942005-09-30 01:36:00 -0400866static void mv_port_stop(struct ata_port *ap)
867{
868 struct device *dev = ap->host_set->dev;
869 struct mv_port_priv *pp = ap->private_data;
Brett Russafb0edd2005-10-05 17:08:42 -0400870 unsigned long flags;
Brett Russ31961942005-09-30 01:36:00 -0400871
Brett Russafb0edd2005-10-05 17:08:42 -0400872 spin_lock_irqsave(&ap->host_set->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400873 mv_stop_dma(ap);
Brett Russafb0edd2005-10-05 17:08:42 -0400874 spin_unlock_irqrestore(&ap->host_set->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400875
876 ap->private_data = NULL;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500877 ata_pad_free(ap, dev);
878 mv_priv_free(pp, dev);
Brett Russ31961942005-09-30 01:36:00 -0400879 kfree(pp);
880}
881
Brett Russ05b308e2005-10-05 17:08:53 -0400882/**
883 * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
884 * @qc: queued command whose SG list to source from
885 *
886 * Populate the SG list and mark the last entry.
887 *
888 * LOCKING:
889 * Inherited from caller.
890 */
Brett Russ31961942005-09-30 01:36:00 -0400891static void mv_fill_sg(struct ata_queued_cmd *qc)
892{
893 struct mv_port_priv *pp = qc->ap->private_data;
Jeff Garzik972c26b2005-10-18 22:14:54 -0400894 unsigned int i = 0;
895 struct scatterlist *sg;
Brett Russ31961942005-09-30 01:36:00 -0400896
Jeff Garzik972c26b2005-10-18 22:14:54 -0400897 ata_for_each_sg(sg, qc) {
Brett Russ31961942005-09-30 01:36:00 -0400898 dma_addr_t addr;
Jeff Garzik22374672005-11-17 10:59:48 -0500899 u32 sg_len, len, offset;
Brett Russ31961942005-09-30 01:36:00 -0400900
Jeff Garzik972c26b2005-10-18 22:14:54 -0400901 addr = sg_dma_address(sg);
902 sg_len = sg_dma_len(sg);
Brett Russ31961942005-09-30 01:36:00 -0400903
Jeff Garzik22374672005-11-17 10:59:48 -0500904 while (sg_len) {
905 offset = addr & MV_DMA_BOUNDARY;
906 len = sg_len;
907 if ((offset + sg_len) > 0x10000)
908 len = 0x10000 - offset;
Jeff Garzik972c26b2005-10-18 22:14:54 -0400909
Jeff Garzik22374672005-11-17 10:59:48 -0500910 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
911 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
912 pp->sg_tbl[i].flags_size = cpu_to_le32(len);
913
914 sg_len -= len;
915 addr += len;
916
917 if (!sg_len && ata_sg_is_last(sg, qc))
918 pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
919
920 i++;
921 }
Brett Russ31961942005-09-30 01:36:00 -0400922 }
923}
924
925static inline unsigned mv_inc_q_index(unsigned *index)
926{
927 *index = (*index + 1) & MV_MAX_Q_DEPTH_MASK;
928 return *index;
929}
930
931static inline void mv_crqb_pack_cmd(u16 *cmdw, u8 data, u8 addr, unsigned last)
932{
933 *cmdw = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
934 (last ? CRQB_CMD_LAST : 0);
935}
936
Brett Russ05b308e2005-10-05 17:08:53 -0400937/**
938 * mv_qc_prep - Host specific command preparation.
939 * @qc: queued command to prepare
940 *
941 * This routine simply redirects to the general purpose routine
942 * if command is not DMA. Else, it handles prep of the CRQB
943 * (command request block), does some sanity checking, and calls
944 * the SG load routine.
945 *
946 * LOCKING:
947 * Inherited from caller.
948 */
Brett Russ31961942005-09-30 01:36:00 -0400949static void mv_qc_prep(struct ata_queued_cmd *qc)
950{
951 struct ata_port *ap = qc->ap;
952 struct mv_port_priv *pp = ap->private_data;
953 u16 *cw;
954 struct ata_taskfile *tf;
955 u16 flags = 0;
956
957 if (ATA_PROT_DMA != qc->tf.protocol) {
958 return;
Brett Russ20f733e2005-09-01 18:26:17 -0400959 }
960
Brett Russ31961942005-09-30 01:36:00 -0400961 /* the req producer index should be the same as we remember it */
Jeff Garzik8b260242005-11-12 12:32:50 -0500962 assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >>
Brett Russ31961942005-09-30 01:36:00 -0400963 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
964 pp->req_producer);
965
966 /* Fill in command request block
967 */
968 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) {
969 flags |= CRQB_FLAG_READ;
970 }
971 assert(MV_MAX_Q_DEPTH > qc->tag);
972 flags |= qc->tag << CRQB_TAG_SHIFT;
973
Jeff Garzik8b260242005-11-12 12:32:50 -0500974 pp->crqb[pp->req_producer].sg_addr =
Brett Russ31961942005-09-30 01:36:00 -0400975 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
Jeff Garzik8b260242005-11-12 12:32:50 -0500976 pp->crqb[pp->req_producer].sg_addr_hi =
Brett Russ31961942005-09-30 01:36:00 -0400977 cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
978 pp->crqb[pp->req_producer].ctrl_flags = cpu_to_le16(flags);
979
980 cw = &pp->crqb[pp->req_producer].ata_cmd[0];
981 tf = &qc->tf;
982
983 /* Sadly, the CRQB cannot accomodate all registers--there are
984 * only 11 bytes...so we must pick and choose required
985 * registers based on the command. So, we drop feature and
986 * hob_feature for [RW] DMA commands, but they are needed for
987 * NCQ. NCQ will drop hob_nsect.
988 */
989 switch (tf->command) {
990 case ATA_CMD_READ:
991 case ATA_CMD_READ_EXT:
992 case ATA_CMD_WRITE:
993 case ATA_CMD_WRITE_EXT:
994 mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
995 break;
996#ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */
997 case ATA_CMD_FPDMA_READ:
998 case ATA_CMD_FPDMA_WRITE:
Jeff Garzik8b260242005-11-12 12:32:50 -0500999 mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
Brett Russ31961942005-09-30 01:36:00 -04001000 mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
1001 break;
1002#endif /* FIXME: remove this line when NCQ added */
1003 default:
1004 /* The only other commands EDMA supports in non-queued and
1005 * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
1006 * of which are defined/used by Linux. If we get here, this
1007 * driver needs work.
1008 *
1009 * FIXME: modify libata to give qc_prep a return value and
1010 * return error here.
1011 */
1012 BUG_ON(tf->command);
1013 break;
1014 }
1015 mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
1016 mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
1017 mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
1018 mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
1019 mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
1020 mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
1021 mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
1022 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
1023 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
1024
1025 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) {
1026 return;
1027 }
1028 mv_fill_sg(qc);
1029}
1030
Brett Russ05b308e2005-10-05 17:08:53 -04001031/**
1032 * mv_qc_issue - Initiate a command to the host
1033 * @qc: queued command to start
1034 *
1035 * This routine simply redirects to the general purpose routine
1036 * if command is not DMA. Else, it sanity checks our local
1037 * caches of the request producer/consumer indices then enables
1038 * DMA and bumps the request producer index.
1039 *
1040 * LOCKING:
1041 * Inherited from caller.
1042 */
Brett Russ31961942005-09-30 01:36:00 -04001043static int mv_qc_issue(struct ata_queued_cmd *qc)
1044{
1045 void __iomem *port_mmio = mv_ap_base(qc->ap);
1046 struct mv_port_priv *pp = qc->ap->private_data;
1047 u32 in_ptr;
1048
1049 if (ATA_PROT_DMA != qc->tf.protocol) {
1050 /* We're about to send a non-EDMA capable command to the
1051 * port. Turn off EDMA so there won't be problems accessing
1052 * shadow block, etc registers.
1053 */
1054 mv_stop_dma(qc->ap);
1055 return ata_qc_issue_prot(qc);
1056 }
1057
1058 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1059
1060 /* the req producer index should be the same as we remember it */
1061 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
1062 pp->req_producer);
1063 /* until we do queuing, the queue should be empty at this point */
1064 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Jeff Garzik8b260242005-11-12 12:32:50 -05001065 ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >>
Brett Russ31961942005-09-30 01:36:00 -04001066 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
1067
1068 mv_inc_q_index(&pp->req_producer); /* now incr producer index */
1069
Brett Russafb0edd2005-10-05 17:08:42 -04001070 mv_start_dma(port_mmio, pp);
Brett Russ31961942005-09-30 01:36:00 -04001071
1072 /* and write the request in pointer to kick the EDMA to life */
1073 in_ptr &= EDMA_REQ_Q_BASE_LO_MASK;
1074 in_ptr |= pp->req_producer << EDMA_REQ_Q_PTR_SHIFT;
1075 writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1076
1077 return 0;
1078}
1079
Brett Russ05b308e2005-10-05 17:08:53 -04001080/**
1081 * mv_get_crpb_status - get status from most recently completed cmd
1082 * @ap: ATA channel to manipulate
1083 *
1084 * This routine is for use when the port is in DMA mode, when it
1085 * will be using the CRPB (command response block) method of
1086 * returning command completion information. We assert indices
1087 * are good, grab status, and bump the response consumer index to
1088 * prove that we're up to date.
1089 *
1090 * LOCKING:
1091 * Inherited from caller.
1092 */
Brett Russ31961942005-09-30 01:36:00 -04001093static u8 mv_get_crpb_status(struct ata_port *ap)
1094{
1095 void __iomem *port_mmio = mv_ap_base(ap);
1096 struct mv_port_priv *pp = ap->private_data;
1097 u32 out_ptr;
1098
1099 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1100
1101 /* the response consumer index should be the same as we remember it */
Jeff Garzik8b260242005-11-12 12:32:50 -05001102 assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Brett Russ31961942005-09-30 01:36:00 -04001103 pp->rsp_consumer);
1104
1105 /* increment our consumer index... */
1106 pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer);
Jeff Garzik8b260242005-11-12 12:32:50 -05001107
Brett Russ31961942005-09-30 01:36:00 -04001108 /* and, until we do NCQ, there should only be 1 CRPB waiting */
Jeff Garzik8b260242005-11-12 12:32:50 -05001109 assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >>
1110 EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Brett Russ31961942005-09-30 01:36:00 -04001111 pp->rsp_consumer);
1112
1113 /* write out our inc'd consumer index so EDMA knows we're caught up */
1114 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
1115 out_ptr |= pp->rsp_consumer << EDMA_RSP_Q_PTR_SHIFT;
1116 writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1117
1118 /* Return ATA status register for completed CRPB */
1119 return (pp->crpb[pp->rsp_consumer].flags >> CRPB_FLAG_STATUS_SHIFT);
Brett Russ20f733e2005-09-01 18:26:17 -04001120}
1121
Brett Russ05b308e2005-10-05 17:08:53 -04001122/**
1123 * mv_err_intr - Handle error interrupts on the port
1124 * @ap: ATA channel to manipulate
1125 *
1126 * In most cases, just clear the interrupt and move on. However,
1127 * some cases require an eDMA reset, which is done right before
1128 * the COMRESET in mv_phy_reset(). The SERR case requires a
1129 * clear of pending errors in the SATA SERROR register. Finally,
1130 * if the port disabled DMA, update our cached copy to match.
1131 *
1132 * LOCKING:
1133 * Inherited from caller.
1134 */
Brett Russ20f733e2005-09-01 18:26:17 -04001135static void mv_err_intr(struct ata_port *ap)
1136{
Brett Russ31961942005-09-30 01:36:00 -04001137 void __iomem *port_mmio = mv_ap_base(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001138 u32 edma_err_cause, serr = 0;
1139
Brett Russ20f733e2005-09-01 18:26:17 -04001140 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1141
1142 if (EDMA_ERR_SERR & edma_err_cause) {
1143 serr = scr_read(ap, SCR_ERROR);
1144 scr_write_flush(ap, SCR_ERROR, serr);
1145 }
Brett Russafb0edd2005-10-05 17:08:42 -04001146 if (EDMA_ERR_SELF_DIS & edma_err_cause) {
1147 struct mv_port_priv *pp = ap->private_data;
1148 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1149 }
1150 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
1151 "SERR: 0x%08x\n", ap->id, edma_err_cause, serr);
Brett Russ20f733e2005-09-01 18:26:17 -04001152
1153 /* Clear EDMA now that SERR cleanup done */
1154 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1155
1156 /* check for fatal here and recover if needed */
1157 if (EDMA_ERR_FATAL & edma_err_cause) {
Jeff Garzikc9d39132005-11-13 17:47:51 -05001158 mv_stop_and_reset(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001159 }
1160}
1161
Brett Russ05b308e2005-10-05 17:08:53 -04001162/**
1163 * mv_host_intr - Handle all interrupts on the given host controller
1164 * @host_set: host specific structure
1165 * @relevant: port error bits relevant to this host controller
1166 * @hc: which host controller we're to look at
1167 *
1168 * Read then write clear the HC interrupt status then walk each
1169 * port connected to the HC and see if it needs servicing. Port
1170 * success ints are reported in the HC interrupt status reg, the
1171 * port error ints are reported in the higher level main
1172 * interrupt status register and thus are passed in via the
1173 * 'relevant' argument.
1174 *
1175 * LOCKING:
1176 * Inherited from caller.
Brett Russ20f733e2005-09-01 18:26:17 -04001177 */
1178static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1179 unsigned int hc)
1180{
1181 void __iomem *mmio = host_set->mmio_base;
1182 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1183 struct ata_port *ap;
1184 struct ata_queued_cmd *qc;
1185 u32 hc_irq_cause;
Brett Russ31961942005-09-30 01:36:00 -04001186 int shift, port, port0, hard_port, handled;
Jeff Garzika7dac442005-10-30 04:44:42 -05001187 unsigned int err_mask;
Brett Russ31961942005-09-30 01:36:00 -04001188 u8 ata_status = 0;
Brett Russ20f733e2005-09-01 18:26:17 -04001189
1190 if (hc == 0) {
1191 port0 = 0;
1192 } else {
1193 port0 = MV_PORTS_PER_HC;
1194 }
1195
1196 /* we'll need the HC success int register in most cases */
1197 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1198 if (hc_irq_cause) {
Brett Russ31961942005-09-30 01:36:00 -04001199 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001200 }
1201
1202 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1203 hc,relevant,hc_irq_cause);
1204
1205 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
1206 ap = host_set->ports[port];
1207 hard_port = port & MV_PORT_MASK; /* range 0-3 */
Brett Russ31961942005-09-30 01:36:00 -04001208 handled = 0; /* ensure ata_status is set if handled++ */
Brett Russ20f733e2005-09-01 18:26:17 -04001209
Brett Russ31961942005-09-30 01:36:00 -04001210 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {
1211 /* new CRPB on the queue; just one at a time until NCQ
1212 */
1213 ata_status = mv_get_crpb_status(ap);
1214 handled++;
1215 } else if ((DEV_IRQ << hard_port) & hc_irq_cause) {
1216 /* received ATA IRQ; read the status reg to clear INTRQ
Brett Russ20f733e2005-09-01 18:26:17 -04001217 */
1218 ata_status = readb((void __iomem *)
1219 ap->ioaddr.status_addr);
Brett Russ31961942005-09-30 01:36:00 -04001220 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001221 }
1222
Jeff Garzikd67e7eb2005-11-18 11:55:00 -05001223 if (ap && (ap->flags & ATA_FLAG_PORT_DISABLED))
Jeff Garzika2c91a82005-11-17 05:44:44 -05001224 continue;
1225
Jeff Garzika7dac442005-10-30 04:44:42 -05001226 err_mask = ac_err_mask(ata_status);
1227
Brett Russ31961942005-09-30 01:36:00 -04001228 shift = port << 1; /* (port * 2) */
Brett Russ20f733e2005-09-01 18:26:17 -04001229 if (port >= MV_PORTS_PER_HC) {
1230 shift++; /* skip bit 8 in the HC Main IRQ reg */
1231 }
1232 if ((PORT0_ERR << shift) & relevant) {
1233 mv_err_intr(ap);
Jeff Garzika7dac442005-10-30 04:44:42 -05001234 err_mask |= AC_ERR_OTHER;
Brett Russ31961942005-09-30 01:36:00 -04001235 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001236 }
Jeff Garzik8b260242005-11-12 12:32:50 -05001237
Brett Russ31961942005-09-30 01:36:00 -04001238 if (handled && ap) {
Brett Russ20f733e2005-09-01 18:26:17 -04001239 qc = ata_qc_from_tag(ap, ap->active_tag);
1240 if (NULL != qc) {
1241 VPRINTK("port %u IRQ found for qc, "
1242 "ata_status 0x%x\n", port,ata_status);
Brett Russ20f733e2005-09-01 18:26:17 -04001243 /* mark qc status appropriately */
Jeff Garzikd67e7eb2005-11-18 11:55:00 -05001244 if (!(qc->tf.flags & ATA_TFLAG_POLLING))
Jeff Garzika2c91a82005-11-17 05:44:44 -05001245 ata_qc_complete(qc, err_mask);
Brett Russ20f733e2005-09-01 18:26:17 -04001246 }
1247 }
1248 }
1249 VPRINTK("EXIT\n");
1250}
1251
Brett Russ05b308e2005-10-05 17:08:53 -04001252/**
Jeff Garzik8b260242005-11-12 12:32:50 -05001253 * mv_interrupt -
Brett Russ05b308e2005-10-05 17:08:53 -04001254 * @irq: unused
1255 * @dev_instance: private data; in this case the host structure
1256 * @regs: unused
1257 *
1258 * Read the read only register to determine if any host
1259 * controllers have pending interrupts. If so, call lower level
1260 * routine to handle. Also check for PCI errors which are only
1261 * reported here.
1262 *
Jeff Garzik8b260242005-11-12 12:32:50 -05001263 * LOCKING:
Brett Russ05b308e2005-10-05 17:08:53 -04001264 * This routine holds the host_set lock while processing pending
1265 * interrupts.
1266 */
Brett Russ20f733e2005-09-01 18:26:17 -04001267static irqreturn_t mv_interrupt(int irq, void *dev_instance,
1268 struct pt_regs *regs)
1269{
1270 struct ata_host_set *host_set = dev_instance;
1271 unsigned int hc, handled = 0, n_hcs;
Brett Russ31961942005-09-30 01:36:00 -04001272 void __iomem *mmio = host_set->mmio_base;
Brett Russ20f733e2005-09-01 18:26:17 -04001273 u32 irq_stat;
1274
Brett Russ20f733e2005-09-01 18:26:17 -04001275 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001276
1277 /* check the cases where we either have nothing pending or have read
1278 * a bogus register value which can indicate HW removal or PCI fault
1279 */
1280 if (!irq_stat || (0xffffffffU == irq_stat)) {
1281 return IRQ_NONE;
1282 }
1283
Brett Russ31961942005-09-30 01:36:00 -04001284 n_hcs = mv_get_hc_count(host_set->ports[0]->flags);
Brett Russ20f733e2005-09-01 18:26:17 -04001285 spin_lock(&host_set->lock);
1286
1287 for (hc = 0; hc < n_hcs; hc++) {
1288 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
1289 if (relevant) {
1290 mv_host_intr(host_set, relevant, hc);
Brett Russ31961942005-09-30 01:36:00 -04001291 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001292 }
1293 }
1294 if (PCI_ERR & irq_stat) {
Brett Russ31961942005-09-30 01:36:00 -04001295 printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n",
1296 readl(mmio + PCI_IRQ_CAUSE_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04001297
Brett Russafb0edd2005-10-05 17:08:42 -04001298 DPRINTK("All regs @ PCI error\n");
Brett Russ31961942005-09-30 01:36:00 -04001299 mv_dump_all_regs(mmio, -1, to_pci_dev(host_set->dev));
1300
1301 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1302 handled++;
1303 }
Brett Russ20f733e2005-09-01 18:26:17 -04001304 spin_unlock(&host_set->lock);
1305
1306 return IRQ_RETVAL(handled);
1307}
1308
Jeff Garzikc9d39132005-11-13 17:47:51 -05001309static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port)
1310{
1311 void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port);
1312 unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL;
1313
1314 return hc_mmio + ofs;
1315}
1316
1317static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
1318{
1319 unsigned int ofs;
1320
1321 switch (sc_reg_in) {
1322 case SCR_STATUS:
1323 case SCR_ERROR:
1324 case SCR_CONTROL:
1325 ofs = sc_reg_in * sizeof(u32);
1326 break;
1327 default:
1328 ofs = 0xffffffffU;
1329 break;
1330 }
1331 return ofs;
1332}
1333
1334static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
1335{
1336 void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no);
1337 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1338
1339 if (ofs != 0xffffffffU)
1340 return readl(mmio + ofs);
1341 else
1342 return (u32) ofs;
1343}
1344
1345static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
1346{
1347 void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no);
1348 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1349
1350 if (ofs != 0xffffffffU)
1351 writelfl(val, mmio + ofs);
1352}
1353
Jeff Garzik522479f2005-11-12 22:14:02 -05001354static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
1355{
1356 u8 rev_id;
1357 int early_5080;
1358
1359 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1360
1361 early_5080 = (pdev->device == 0x5080) && (rev_id == 0);
1362
1363 if (!early_5080) {
1364 u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1365 tmp |= (1 << 0);
1366 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
1367 }
1368
1369 mv_reset_pci_bus(pdev, mmio);
1370}
1371
1372static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1373{
1374 writel(0x0fcfffff, mmio + MV_FLASH_CTL);
1375}
1376
Jeff Garzik47c2b672005-11-12 21:13:17 -05001377static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001378 void __iomem *mmio)
1379{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001380 void __iomem *phy_mmio = mv5_phy_base(mmio, idx);
1381 u32 tmp;
1382
1383 tmp = readl(phy_mmio + MV5_PHY_MODE);
1384
1385 hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */
1386 hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001387}
1388
Jeff Garzik47c2b672005-11-12 21:13:17 -05001389static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001390{
Jeff Garzik522479f2005-11-12 22:14:02 -05001391 u32 tmp;
1392
1393 writel(0, mmio + MV_GPIO_PORT_CTL);
1394
1395 /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */
1396
1397 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1398 tmp |= ~(1 << 0);
1399 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001400}
1401
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001402static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
1403 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001404{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001405 void __iomem *phy_mmio = mv5_phy_base(mmio, port);
1406 const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5);
1407 u32 tmp;
1408 int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0);
1409
1410 if (fix_apm_sq) {
1411 tmp = readl(phy_mmio + MV5_LT_MODE);
1412 tmp |= (1 << 19);
1413 writel(tmp, phy_mmio + MV5_LT_MODE);
1414
1415 tmp = readl(phy_mmio + MV5_PHY_CTL);
1416 tmp &= ~0x3;
1417 tmp |= 0x1;
1418 writel(tmp, phy_mmio + MV5_PHY_CTL);
1419 }
1420
1421 tmp = readl(phy_mmio + MV5_PHY_MODE);
1422 tmp &= ~mask;
1423 tmp |= hpriv->signal[port].pre;
1424 tmp |= hpriv->signal[port].amps;
1425 writel(tmp, phy_mmio + MV5_PHY_MODE);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001426}
1427
Jeff Garzikc9d39132005-11-13 17:47:51 -05001428
1429#undef ZERO
1430#define ZERO(reg) writel(0, port_mmio + (reg))
1431static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio,
1432 unsigned int port)
Jeff Garzik47c2b672005-11-12 21:13:17 -05001433{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001434 void __iomem *port_mmio = mv_port_base(mmio, port);
1435
1436 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
1437
1438 mv_channel_reset(hpriv, mmio, port);
1439
1440 ZERO(0x028); /* command */
1441 writel(0x11f, port_mmio + EDMA_CFG_OFS);
1442 ZERO(0x004); /* timer */
1443 ZERO(0x008); /* irq err cause */
1444 ZERO(0x00c); /* irq err mask */
1445 ZERO(0x010); /* rq bah */
1446 ZERO(0x014); /* rq inp */
1447 ZERO(0x018); /* rq outp */
1448 ZERO(0x01c); /* respq bah */
1449 ZERO(0x024); /* respq outp */
1450 ZERO(0x020); /* respq inp */
1451 ZERO(0x02c); /* test control */
1452 writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
1453}
1454#undef ZERO
1455
1456#define ZERO(reg) writel(0, hc_mmio + (reg))
1457static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1458 unsigned int hc)
1459{
1460 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1461 u32 tmp;
1462
1463 ZERO(0x00c);
1464 ZERO(0x010);
1465 ZERO(0x014);
1466 ZERO(0x018);
1467
1468 tmp = readl(hc_mmio + 0x20);
1469 tmp &= 0x1c1c1c1c;
1470 tmp |= 0x03030303;
1471 writel(tmp, hc_mmio + 0x20);
1472}
1473#undef ZERO
1474
1475static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1476 unsigned int n_hc)
1477{
1478 unsigned int hc, port;
1479
1480 for (hc = 0; hc < n_hc; hc++) {
1481 for (port = 0; port < MV_PORTS_PER_HC; port++)
1482 mv5_reset_hc_port(hpriv, mmio,
1483 (hc * MV_PORTS_PER_HC) + port);
1484
1485 mv5_reset_one_hc(hpriv, mmio, hc);
1486 }
1487
1488 return 0;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001489}
1490
Jeff Garzik101ffae2005-11-12 22:17:49 -05001491#undef ZERO
1492#define ZERO(reg) writel(0, mmio + (reg))
1493static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
1494{
1495 u32 tmp;
1496
1497 tmp = readl(mmio + MV_PCI_MODE);
1498 tmp &= 0xff00ffff;
1499 writel(tmp, mmio + MV_PCI_MODE);
1500
1501 ZERO(MV_PCI_DISC_TIMER);
1502 ZERO(MV_PCI_MSI_TRIGGER);
1503 writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT);
1504 ZERO(HC_MAIN_IRQ_MASK_OFS);
1505 ZERO(MV_PCI_SERR_MASK);
1506 ZERO(PCI_IRQ_CAUSE_OFS);
1507 ZERO(PCI_IRQ_MASK_OFS);
1508 ZERO(MV_PCI_ERR_LOW_ADDRESS);
1509 ZERO(MV_PCI_ERR_HIGH_ADDRESS);
1510 ZERO(MV_PCI_ERR_ATTRIBUTE);
1511 ZERO(MV_PCI_ERR_COMMAND);
1512}
1513#undef ZERO
1514
1515static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1516{
1517 u32 tmp;
1518
1519 mv5_reset_flash(hpriv, mmio);
1520
1521 tmp = readl(mmio + MV_GPIO_PORT_CTL);
1522 tmp &= 0x3;
1523 tmp |= (1 << 5) | (1 << 6);
1524 writel(tmp, mmio + MV_GPIO_PORT_CTL);
1525}
1526
Brett Russ05b308e2005-10-05 17:08:53 -04001527/**
Jeff Garzik101ffae2005-11-12 22:17:49 -05001528 * mv6_reset_hc - Perform the 6xxx global soft reset
1529 * @mmio: base address of the HBA
1530 *
1531 * This routine only applies to 6xxx parts.
1532 *
1533 * LOCKING:
1534 * Inherited from caller.
1535 */
Jeff Garzikc9d39132005-11-13 17:47:51 -05001536static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1537 unsigned int n_hc)
Jeff Garzik101ffae2005-11-12 22:17:49 -05001538{
1539 void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS;
1540 int i, rc = 0;
1541 u32 t;
1542
1543 /* Following procedure defined in PCI "main command and status
1544 * register" table.
1545 */
1546 t = readl(reg);
1547 writel(t | STOP_PCI_MASTER, reg);
1548
1549 for (i = 0; i < 1000; i++) {
1550 udelay(1);
1551 t = readl(reg);
1552 if (PCI_MASTER_EMPTY & t) {
1553 break;
1554 }
1555 }
1556 if (!(PCI_MASTER_EMPTY & t)) {
1557 printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
1558 rc = 1;
1559 goto done;
1560 }
1561
1562 /* set reset */
1563 i = 5;
1564 do {
1565 writel(t | GLOB_SFT_RST, reg);
1566 t = readl(reg);
1567 udelay(1);
1568 } while (!(GLOB_SFT_RST & t) && (i-- > 0));
1569
1570 if (!(GLOB_SFT_RST & t)) {
1571 printk(KERN_ERR DRV_NAME ": can't set global reset\n");
1572 rc = 1;
1573 goto done;
1574 }
1575
1576 /* clear reset and *reenable the PCI master* (not mentioned in spec) */
1577 i = 5;
1578 do {
1579 writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
1580 t = readl(reg);
1581 udelay(1);
1582 } while ((GLOB_SFT_RST & t) && (i-- > 0));
1583
1584 if (GLOB_SFT_RST & t) {
1585 printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
1586 rc = 1;
1587 }
1588done:
1589 return rc;
1590}
1591
Jeff Garzik47c2b672005-11-12 21:13:17 -05001592static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001593 void __iomem *mmio)
1594{
1595 void __iomem *port_mmio;
1596 u32 tmp;
1597
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001598 tmp = readl(mmio + MV_RESET_CFG);
1599 if ((tmp & (1 << 0)) == 0) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001600 hpriv->signal[idx].amps = 0x7 << 8;
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001601 hpriv->signal[idx].pre = 0x1 << 5;
1602 return;
1603 }
1604
1605 port_mmio = mv_port_base(mmio, idx);
1606 tmp = readl(port_mmio + PHY_MODE2);
1607
1608 hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
1609 hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
1610}
1611
Jeff Garzik47c2b672005-11-12 21:13:17 -05001612static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001613{
Jeff Garzik47c2b672005-11-12 21:13:17 -05001614 writel(0x00000060, mmio + MV_GPIO_PORT_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001615}
1616
Jeff Garzikc9d39132005-11-13 17:47:51 -05001617static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001618 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001619{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001620 void __iomem *port_mmio = mv_port_base(mmio, port);
1621
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001622 u32 hp_flags = hpriv->hp_flags;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001623 int fix_phy_mode2 =
1624 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001625 int fix_phy_mode4 =
Jeff Garzik47c2b672005-11-12 21:13:17 -05001626 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
1627 u32 m2, tmp;
1628
1629 if (fix_phy_mode2) {
1630 m2 = readl(port_mmio + PHY_MODE2);
1631 m2 &= ~(1 << 16);
1632 m2 |= (1 << 31);
1633 writel(m2, port_mmio + PHY_MODE2);
1634
1635 udelay(200);
1636
1637 m2 = readl(port_mmio + PHY_MODE2);
1638 m2 &= ~((1 << 16) | (1 << 31));
1639 writel(m2, port_mmio + PHY_MODE2);
1640
1641 udelay(200);
1642 }
1643
1644 /* who knows what this magic does */
1645 tmp = readl(port_mmio + PHY_MODE3);
1646 tmp &= ~0x7F800000;
1647 tmp |= 0x2A800000;
1648 writel(tmp, port_mmio + PHY_MODE3);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001649
1650 if (fix_phy_mode4) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001651 u32 m4;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001652
1653 m4 = readl(port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001654
1655 if (hp_flags & MV_HP_ERRATA_60X1B2)
1656 tmp = readl(port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001657
1658 m4 = (m4 & ~(1 << 1)) | (1 << 0);
1659
1660 writel(m4, port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001661
1662 if (hp_flags & MV_HP_ERRATA_60X1B2)
1663 writel(tmp, port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001664 }
1665
1666 /* Revert values of pre-emphasis and signal amps to the saved ones */
1667 m2 = readl(port_mmio + PHY_MODE2);
1668
1669 m2 &= ~MV_M2_PREAMP_MASK;
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001670 m2 |= hpriv->signal[port].amps;
1671 m2 |= hpriv->signal[port].pre;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001672 m2 &= ~(1 << 16);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001673
1674 writel(m2, port_mmio + PHY_MODE2);
1675}
1676
Jeff Garzikc9d39132005-11-13 17:47:51 -05001677static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1678 unsigned int port_no)
Brett Russ20f733e2005-09-01 18:26:17 -04001679{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001680 void __iomem *port_mmio = mv_port_base(mmio, port_no);
Brett Russ20f733e2005-09-01 18:26:17 -04001681
Brett Russ31961942005-09-30 01:36:00 -04001682 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001683
1684 if (IS_60XX(hpriv)) {
1685 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
1686 ifctl |= (1 << 12) | (1 << 7);
1687 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
1688 }
1689
Brett Russ20f733e2005-09-01 18:26:17 -04001690 udelay(25); /* allow reset propagation */
1691
1692 /* Spec never mentions clearing the bit. Marvell's driver does
1693 * clear the bit, however.
1694 */
Brett Russ31961942005-09-30 01:36:00 -04001695 writelfl(0, port_mmio + EDMA_CMD_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001696
Jeff Garzikc9d39132005-11-13 17:47:51 -05001697 hpriv->ops->phy_errata(hpriv, mmio, port_no);
1698
1699 if (IS_50XX(hpriv))
1700 mdelay(1);
1701}
1702
1703static void mv_stop_and_reset(struct ata_port *ap)
1704{
1705 struct mv_host_priv *hpriv = ap->host_set->private_data;
1706 void __iomem *mmio = ap->host_set->mmio_base;
1707
1708 mv_stop_dma(ap);
1709
1710 mv_channel_reset(hpriv, mmio, ap->port_no);
1711
Jeff Garzik22374672005-11-17 10:59:48 -05001712 __mv_phy_reset(ap, 0);
1713}
1714
1715static inline void __msleep(unsigned int msec, int can_sleep)
1716{
1717 if (can_sleep)
1718 msleep(msec);
1719 else
1720 mdelay(msec);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001721}
1722
1723/**
Jeff Garzik22374672005-11-17 10:59:48 -05001724 * __mv_phy_reset - Perform eDMA reset followed by COMRESET
Brett Russ20f733e2005-09-01 18:26:17 -04001725 * @ap: ATA channel to manipulate
1726 *
1727 * Part of this is taken from __sata_phy_reset and modified to
1728 * not sleep since this routine gets called from interrupt level.
1729 *
1730 * LOCKING:
1731 * Inherited from caller. This is coded to safe to call at
1732 * interrupt level, i.e. it does not sleep.
1733 */
Jeff Garzik22374672005-11-17 10:59:48 -05001734static void __mv_phy_reset(struct ata_port *ap, int can_sleep)
Brett Russ20f733e2005-09-01 18:26:17 -04001735{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001736 struct mv_port_priv *pp = ap->private_data;
Jeff Garzik22374672005-11-17 10:59:48 -05001737 struct mv_host_priv *hpriv = ap->host_set->private_data;
Brett Russ20f733e2005-09-01 18:26:17 -04001738 void __iomem *port_mmio = mv_ap_base(ap);
1739 struct ata_taskfile tf;
1740 struct ata_device *dev = &ap->device[0];
Brett Russ20f733e2005-09-01 18:26:17 -04001741 unsigned long timeout;
Jeff Garzik22374672005-11-17 10:59:48 -05001742 int retry = 5;
1743 u32 sstatus;
Brett Russ20f733e2005-09-01 18:26:17 -04001744
1745 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
1746
Jeff Garzik095fec82005-11-12 09:50:49 -05001747 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001748 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1749 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
Brett Russ20f733e2005-09-01 18:26:17 -04001750
Jeff Garzik22374672005-11-17 10:59:48 -05001751 /* Issue COMRESET via SControl */
1752comreset_retry:
Brett Russ31961942005-09-30 01:36:00 -04001753 scr_write_flush(ap, SCR_CONTROL, 0x301);
Jeff Garzik22374672005-11-17 10:59:48 -05001754 __msleep(1, can_sleep);
1755
Brett Russ31961942005-09-30 01:36:00 -04001756 scr_write_flush(ap, SCR_CONTROL, 0x300);
Jeff Garzik22374672005-11-17 10:59:48 -05001757 __msleep(20, can_sleep);
1758
1759 timeout = jiffies + msecs_to_jiffies(200);
Brett Russ31961942005-09-30 01:36:00 -04001760 do {
Jeff Garzik22374672005-11-17 10:59:48 -05001761 sstatus = scr_read(ap, SCR_STATUS) & 0x3;
1762 if ((sstatus == 3) || (sstatus == 0))
Brett Russ31961942005-09-30 01:36:00 -04001763 break;
Jeff Garzik22374672005-11-17 10:59:48 -05001764
1765 __msleep(1, can_sleep);
Brett Russ31961942005-09-30 01:36:00 -04001766 } while (time_before(jiffies, timeout));
Brett Russ20f733e2005-09-01 18:26:17 -04001767
Jeff Garzik22374672005-11-17 10:59:48 -05001768 /* work around errata */
1769 if (IS_60XX(hpriv) &&
1770 (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) &&
1771 (retry-- > 0))
1772 goto comreset_retry;
Jeff Garzik095fec82005-11-12 09:50:49 -05001773
1774 DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001775 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1776 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
1777
1778 if (sata_dev_present(ap)) {
1779 ata_port_probe(ap);
1780 } else {
1781 printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n",
1782 ap->id, scr_read(ap, SCR_STATUS));
1783 ata_port_disable(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001784 return;
1785 }
Brett Russ31961942005-09-30 01:36:00 -04001786 ap->cbl = ATA_CBL_SATA;
Brett Russ20f733e2005-09-01 18:26:17 -04001787
Jeff Garzik22374672005-11-17 10:59:48 -05001788 /* even after SStatus reflects that device is ready,
1789 * it seems to take a while for link to be fully
1790 * established (and thus Status no longer 0x80/0x7F),
1791 * so we poll a bit for that, here.
1792 */
1793 retry = 20;
1794 while (1) {
1795 u8 drv_stat = ata_check_status(ap);
1796 if ((drv_stat != 0x80) && (drv_stat != 0x7f))
1797 break;
1798 __msleep(500, can_sleep);
1799 if (retry-- <= 0)
1800 break;
1801 }
1802
Brett Russ20f733e2005-09-01 18:26:17 -04001803 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr);
1804 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr);
1805 tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr);
1806 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr);
1807
1808 dev->class = ata_dev_classify(&tf);
1809 if (!ata_dev_present(dev)) {
1810 VPRINTK("Port disabled post-sig: No device present.\n");
1811 ata_port_disable(ap);
1812 }
Jeff Garzik095fec82005-11-12 09:50:49 -05001813
1814 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1815
1816 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1817
Brett Russ20f733e2005-09-01 18:26:17 -04001818 VPRINTK("EXIT\n");
1819}
1820
Jeff Garzik22374672005-11-17 10:59:48 -05001821static void mv_phy_reset(struct ata_port *ap)
1822{
1823 __mv_phy_reset(ap, 1);
1824}
1825
Brett Russ05b308e2005-10-05 17:08:53 -04001826/**
1827 * mv_eng_timeout - Routine called by libata when SCSI times out I/O
1828 * @ap: ATA channel to manipulate
1829 *
1830 * Intent is to clear all pending error conditions, reset the
1831 * chip/bus, fail the command, and move on.
1832 *
1833 * LOCKING:
1834 * This routine holds the host_set lock while failing the command.
1835 */
Brett Russ31961942005-09-30 01:36:00 -04001836static void mv_eng_timeout(struct ata_port *ap)
Brett Russ20f733e2005-09-01 18:26:17 -04001837{
Brett Russ31961942005-09-30 01:36:00 -04001838 struct ata_queued_cmd *qc;
1839 unsigned long flags;
Brett Russ20f733e2005-09-01 18:26:17 -04001840
Brett Russ31961942005-09-30 01:36:00 -04001841 printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id);
1842 DPRINTK("All regs @ start of eng_timeout\n");
Jeff Garzik8b260242005-11-12 12:32:50 -05001843 mv_dump_all_regs(ap->host_set->mmio_base, ap->port_no,
Brett Russ31961942005-09-30 01:36:00 -04001844 to_pci_dev(ap->host_set->dev));
Brett Russ20f733e2005-09-01 18:26:17 -04001845
Brett Russ31961942005-09-30 01:36:00 -04001846 qc = ata_qc_from_tag(ap, ap->active_tag);
1847 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
Jeff Garzik8b260242005-11-12 12:32:50 -05001848 ap->host_set->mmio_base, ap, qc, qc->scsicmd,
Brett Russ31961942005-09-30 01:36:00 -04001849 &qc->scsicmd->cmnd);
1850
1851 mv_err_intr(ap);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001852 mv_stop_and_reset(ap);
Brett Russ31961942005-09-30 01:36:00 -04001853
1854 if (!qc) {
1855 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
1856 ap->id);
1857 } else {
1858 /* hack alert! We cannot use the supplied completion
1859 * function from inside the ->eh_strategy_handler() thread.
1860 * libata is the only user of ->eh_strategy_handler() in
1861 * any kernel, so the default scsi_done() assumes it is
1862 * not being called from the SCSI EH.
1863 */
1864 spin_lock_irqsave(&ap->host_set->lock, flags);
1865 qc->scsidone = scsi_finish_command;
Jeff Garzika7dac442005-10-30 04:44:42 -05001866 ata_qc_complete(qc, AC_ERR_OTHER);
Brett Russ31961942005-09-30 01:36:00 -04001867 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1868 }
Brett Russ20f733e2005-09-01 18:26:17 -04001869}
1870
Brett Russ05b308e2005-10-05 17:08:53 -04001871/**
1872 * mv_port_init - Perform some early initialization on a single port.
1873 * @port: libata data structure storing shadow register addresses
1874 * @port_mmio: base address of the port
1875 *
1876 * Initialize shadow register mmio addresses, clear outstanding
1877 * interrupts on the port, and unmask interrupts for the future
1878 * start of the port.
1879 *
1880 * LOCKING:
1881 * Inherited from caller.
1882 */
Brett Russ31961942005-09-30 01:36:00 -04001883static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
1884{
1885 unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS;
1886 unsigned serr_ofs;
1887
Jeff Garzik8b260242005-11-12 12:32:50 -05001888 /* PIO related setup
Brett Russ31961942005-09-30 01:36:00 -04001889 */
1890 port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
Jeff Garzik8b260242005-11-12 12:32:50 -05001891 port->error_addr =
Brett Russ31961942005-09-30 01:36:00 -04001892 port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
1893 port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
1894 port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
1895 port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
1896 port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
1897 port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
Jeff Garzik8b260242005-11-12 12:32:50 -05001898 port->status_addr =
Brett Russ31961942005-09-30 01:36:00 -04001899 port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
1900 /* special case: control/altstatus doesn't have ATA_REG_ address */
1901 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
1902
1903 /* unused: */
Brett Russ20f733e2005-09-01 18:26:17 -04001904 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0;
1905
Brett Russ31961942005-09-30 01:36:00 -04001906 /* Clear any currently outstanding port interrupt conditions */
1907 serr_ofs = mv_scr_offset(SCR_ERROR);
1908 writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
1909 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1910
Brett Russ20f733e2005-09-01 18:26:17 -04001911 /* unmask all EDMA error interrupts */
Brett Russ31961942005-09-30 01:36:00 -04001912 writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001913
Jeff Garzik8b260242005-11-12 12:32:50 -05001914 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
Brett Russ31961942005-09-30 01:36:00 -04001915 readl(port_mmio + EDMA_CFG_OFS),
1916 readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
1917 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04001918}
1919
Jeff Garzik47c2b672005-11-12 21:13:17 -05001920static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
Jeff Garzik522479f2005-11-12 22:14:02 -05001921 unsigned int board_idx)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001922{
1923 u8 rev_id;
1924 u32 hp_flags = hpriv->hp_flags;
1925
1926 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1927
1928 switch(board_idx) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001929 case chip_5080:
1930 hpriv->ops = &mv5xxx_ops;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001931 hp_flags |= MV_HP_50XX;
1932
Jeff Garzik47c2b672005-11-12 21:13:17 -05001933 switch (rev_id) {
1934 case 0x1:
1935 hp_flags |= MV_HP_ERRATA_50XXB0;
1936 break;
1937 case 0x3:
1938 hp_flags |= MV_HP_ERRATA_50XXB2;
1939 break;
1940 default:
1941 dev_printk(KERN_WARNING, &pdev->dev,
1942 "Applying 50XXB2 workarounds to unknown rev\n");
1943 hp_flags |= MV_HP_ERRATA_50XXB2;
1944 break;
1945 }
1946 break;
1947
1948 case chip_504x:
1949 case chip_508x:
1950 hpriv->ops = &mv5xxx_ops;
1951 hp_flags |= MV_HP_50XX;
1952
1953 switch (rev_id) {
1954 case 0x0:
1955 hp_flags |= MV_HP_ERRATA_50XXB0;
1956 break;
1957 case 0x3:
1958 hp_flags |= MV_HP_ERRATA_50XXB2;
1959 break;
1960 default:
1961 dev_printk(KERN_WARNING, &pdev->dev,
1962 "Applying B2 workarounds to unknown rev\n");
1963 hp_flags |= MV_HP_ERRATA_50XXB2;
1964 break;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001965 }
1966 break;
1967
1968 case chip_604x:
1969 case chip_608x:
Jeff Garzik47c2b672005-11-12 21:13:17 -05001970 hpriv->ops = &mv6xxx_ops;
1971
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001972 switch (rev_id) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001973 case 0x7:
1974 hp_flags |= MV_HP_ERRATA_60X1B2;
1975 break;
1976 case 0x9:
1977 hp_flags |= MV_HP_ERRATA_60X1C0;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001978 break;
1979 default:
1980 dev_printk(KERN_WARNING, &pdev->dev,
Jeff Garzik47c2b672005-11-12 21:13:17 -05001981 "Applying B2 workarounds to unknown rev\n");
1982 hp_flags |= MV_HP_ERRATA_60X1B2;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001983 break;
1984 }
1985 break;
1986
1987 default:
1988 printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx);
1989 return 1;
1990 }
1991
1992 hpriv->hp_flags = hp_flags;
1993
1994 return 0;
1995}
1996
Brett Russ05b308e2005-10-05 17:08:53 -04001997/**
Jeff Garzik47c2b672005-11-12 21:13:17 -05001998 * mv_init_host - Perform some early initialization of the host.
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001999 * @pdev: host PCI device
Brett Russ05b308e2005-10-05 17:08:53 -04002000 * @probe_ent: early data struct representing the host
2001 *
2002 * If possible, do an early global reset of the host. Then do
2003 * our port init and clear/unmask all/relevant host interrupts.
2004 *
2005 * LOCKING:
2006 * Inherited from caller.
2007 */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002008static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002009 unsigned int board_idx)
Brett Russ20f733e2005-09-01 18:26:17 -04002010{
2011 int rc = 0, n_hc, port, hc;
2012 void __iomem *mmio = probe_ent->mmio_base;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002013 struct mv_host_priv *hpriv = probe_ent->private_data;
Brett Russ20f733e2005-09-01 18:26:17 -04002014
Jeff Garzik47c2b672005-11-12 21:13:17 -05002015 /* global interrupt mask */
2016 writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
2017
2018 rc = mv_chip_id(pdev, hpriv, board_idx);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002019 if (rc)
Brett Russ20f733e2005-09-01 18:26:17 -04002020 goto done;
Brett Russ20f733e2005-09-01 18:26:17 -04002021
2022 n_hc = mv_get_hc_count(probe_ent->host_flags);
2023 probe_ent->n_ports = MV_PORTS_PER_HC * n_hc;
2024
Jeff Garzik47c2b672005-11-12 21:13:17 -05002025 for (port = 0; port < probe_ent->n_ports; port++)
2026 hpriv->ops->read_preamp(hpriv, port, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002027
Jeff Garzikc9d39132005-11-13 17:47:51 -05002028 rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002029 if (rc)
Brett Russ20f733e2005-09-01 18:26:17 -04002030 goto done;
Brett Russ20f733e2005-09-01 18:26:17 -04002031
Jeff Garzik522479f2005-11-12 22:14:02 -05002032 hpriv->ops->reset_flash(hpriv, mmio);
2033 hpriv->ops->reset_bus(pdev, mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002034 hpriv->ops->enable_leds(hpriv, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002035
2036 for (port = 0; port < probe_ent->n_ports; port++) {
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002037 if (IS_60XX(hpriv)) {
Jeff Garzikc9d39132005-11-13 17:47:51 -05002038 void __iomem *port_mmio = mv_port_base(mmio, port);
2039
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002040 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
2041 ifctl |= (1 << 12);
2042 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
2043 }
2044
Jeff Garzikc9d39132005-11-13 17:47:51 -05002045 hpriv->ops->phy_errata(hpriv, mmio, port);
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002046 }
2047
2048 for (port = 0; port < probe_ent->n_ports; port++) {
2049 void __iomem *port_mmio = mv_port_base(mmio, port);
Brett Russ31961942005-09-30 01:36:00 -04002050 mv_port_init(&probe_ent->port[port], port_mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002051 }
2052
2053 for (hc = 0; hc < n_hc; hc++) {
Brett Russ31961942005-09-30 01:36:00 -04002054 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
2055
2056 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
2057 "(before clear)=0x%08x\n", hc,
2058 readl(hc_mmio + HC_CFG_OFS),
2059 readl(hc_mmio + HC_IRQ_CAUSE_OFS));
2060
2061 /* Clear any currently outstanding hc interrupt conditions */
2062 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002063 }
2064
Brett Russ31961942005-09-30 01:36:00 -04002065 /* Clear any currently outstanding host interrupt conditions */
2066 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
2067
2068 /* and unmask interrupt generation for host regs */
2069 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
2070 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002071
2072 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
Jeff Garzik8b260242005-11-12 12:32:50 -05002073 "PCI int cause/mask=0x%08x/0x%08x\n",
Brett Russ20f733e2005-09-01 18:26:17 -04002074 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
2075 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
2076 readl(mmio + PCI_IRQ_CAUSE_OFS),
2077 readl(mmio + PCI_IRQ_MASK_OFS));
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002078
Brett Russ31961942005-09-30 01:36:00 -04002079done:
Brett Russ20f733e2005-09-01 18:26:17 -04002080 return rc;
2081}
2082
Brett Russ05b308e2005-10-05 17:08:53 -04002083/**
2084 * mv_print_info - Dump key info to kernel log for perusal.
2085 * @probe_ent: early data struct representing the host
2086 *
2087 * FIXME: complete this.
2088 *
2089 * LOCKING:
2090 * Inherited from caller.
2091 */
Brett Russ31961942005-09-30 01:36:00 -04002092static void mv_print_info(struct ata_probe_ent *probe_ent)
2093{
2094 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
2095 struct mv_host_priv *hpriv = probe_ent->private_data;
2096 u8 rev_id, scc;
2097 const char *scc_s;
2098
2099 /* Use this to determine the HW stepping of the chip so we know
2100 * what errata to workaround
2101 */
2102 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
2103
2104 pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
2105 if (scc == 0)
2106 scc_s = "SCSI";
2107 else if (scc == 0x01)
2108 scc_s = "RAID";
2109 else
2110 scc_s = "unknown";
2111
Jeff Garzika9524a72005-10-30 14:39:11 -05002112 dev_printk(KERN_INFO, &pdev->dev,
2113 "%u slots %u ports %s mode IRQ via %s\n",
Jeff Garzik8b260242005-11-12 12:32:50 -05002114 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports,
Brett Russ31961942005-09-30 01:36:00 -04002115 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
2116}
2117
Brett Russ05b308e2005-10-05 17:08:53 -04002118/**
2119 * mv_init_one - handle a positive probe of a Marvell host
2120 * @pdev: PCI device found
2121 * @ent: PCI device ID entry for the matched host
2122 *
2123 * LOCKING:
2124 * Inherited from caller.
2125 */
Brett Russ20f733e2005-09-01 18:26:17 -04002126static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2127{
2128 static int printed_version = 0;
2129 struct ata_probe_ent *probe_ent = NULL;
2130 struct mv_host_priv *hpriv;
2131 unsigned int board_idx = (unsigned int)ent->driver_data;
2132 void __iomem *mmio_base;
Brett Russ31961942005-09-30 01:36:00 -04002133 int pci_dev_busy = 0, rc;
Brett Russ20f733e2005-09-01 18:26:17 -04002134
Jeff Garzika9524a72005-10-30 14:39:11 -05002135 if (!printed_version++)
2136 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
Brett Russ20f733e2005-09-01 18:26:17 -04002137
Brett Russ20f733e2005-09-01 18:26:17 -04002138 rc = pci_enable_device(pdev);
2139 if (rc) {
2140 return rc;
2141 }
2142
2143 rc = pci_request_regions(pdev, DRV_NAME);
2144 if (rc) {
2145 pci_dev_busy = 1;
2146 goto err_out;
2147 }
2148
Brett Russ20f733e2005-09-01 18:26:17 -04002149 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
2150 if (probe_ent == NULL) {
2151 rc = -ENOMEM;
2152 goto err_out_regions;
2153 }
2154
2155 memset(probe_ent, 0, sizeof(*probe_ent));
2156 probe_ent->dev = pci_dev_to_dev(pdev);
2157 INIT_LIST_HEAD(&probe_ent->node);
2158
Brett Russ31961942005-09-30 01:36:00 -04002159 mmio_base = pci_iomap(pdev, MV_PRIMARY_BAR, 0);
Brett Russ20f733e2005-09-01 18:26:17 -04002160 if (mmio_base == NULL) {
2161 rc = -ENOMEM;
2162 goto err_out_free_ent;
2163 }
2164
2165 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
2166 if (!hpriv) {
2167 rc = -ENOMEM;
2168 goto err_out_iounmap;
2169 }
2170 memset(hpriv, 0, sizeof(*hpriv));
2171
2172 probe_ent->sht = mv_port_info[board_idx].sht;
2173 probe_ent->host_flags = mv_port_info[board_idx].host_flags;
2174 probe_ent->pio_mask = mv_port_info[board_idx].pio_mask;
2175 probe_ent->udma_mask = mv_port_info[board_idx].udma_mask;
2176 probe_ent->port_ops = mv_port_info[board_idx].port_ops;
2177
2178 probe_ent->irq = pdev->irq;
2179 probe_ent->irq_flags = SA_SHIRQ;
2180 probe_ent->mmio_base = mmio_base;
2181 probe_ent->private_data = hpriv;
2182
2183 /* initialize adapter */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002184 rc = mv_init_host(pdev, probe_ent, board_idx);
Brett Russ20f733e2005-09-01 18:26:17 -04002185 if (rc) {
2186 goto err_out_hpriv;
2187 }
Brett Russ20f733e2005-09-01 18:26:17 -04002188
Brett Russ31961942005-09-30 01:36:00 -04002189 /* Enable interrupts */
2190 if (pci_enable_msi(pdev) == 0) {
2191 hpriv->hp_flags |= MV_HP_FLAG_MSI;
2192 } else {
2193 pci_intx(pdev, 1);
Brett Russ20f733e2005-09-01 18:26:17 -04002194 }
2195
Brett Russ31961942005-09-30 01:36:00 -04002196 mv_dump_pci_cfg(pdev, 0x68);
2197 mv_print_info(probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002198
Brett Russ31961942005-09-30 01:36:00 -04002199 if (ata_device_add(probe_ent) == 0) {
2200 rc = -ENODEV; /* No devices discovered */
2201 goto err_out_dev_add;
2202 }
2203
2204 kfree(probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002205 return 0;
2206
Brett Russ31961942005-09-30 01:36:00 -04002207err_out_dev_add:
2208 if (MV_HP_FLAG_MSI & hpriv->hp_flags) {
2209 pci_disable_msi(pdev);
2210 } else {
2211 pci_intx(pdev, 0);
2212 }
2213err_out_hpriv:
Brett Russ20f733e2005-09-01 18:26:17 -04002214 kfree(hpriv);
Brett Russ31961942005-09-30 01:36:00 -04002215err_out_iounmap:
2216 pci_iounmap(pdev, mmio_base);
2217err_out_free_ent:
Brett Russ20f733e2005-09-01 18:26:17 -04002218 kfree(probe_ent);
Brett Russ31961942005-09-30 01:36:00 -04002219err_out_regions:
Brett Russ20f733e2005-09-01 18:26:17 -04002220 pci_release_regions(pdev);
Brett Russ31961942005-09-30 01:36:00 -04002221err_out:
Brett Russ20f733e2005-09-01 18:26:17 -04002222 if (!pci_dev_busy) {
2223 pci_disable_device(pdev);
2224 }
2225
2226 return rc;
2227}
2228
2229static int __init mv_init(void)
2230{
2231 return pci_module_init(&mv_pci_driver);
2232}
2233
2234static void __exit mv_exit(void)
2235{
2236 pci_unregister_driver(&mv_pci_driver);
2237}
2238
2239MODULE_AUTHOR("Brett Russ");
2240MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
2241MODULE_LICENSE("GPL");
2242MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
2243MODULE_VERSION(DRV_VERSION);
2244
2245module_init(mv_init);
2246module_exit(mv_exit);