blob: ee0634da08720f4054f3e49f4bd1ac2570e7b335 [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 |
88 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO),
Jeff Garzik47c2b672005-11-12 21:13:17 -050089 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
Brett Russ20f733e2005-09-01 18:26:17 -040090
Brett Russ31961942005-09-30 01:36:00 -040091 CRQB_FLAG_READ = (1 << 0),
92 CRQB_TAG_SHIFT = 1,
93 CRQB_CMD_ADDR_SHIFT = 8,
94 CRQB_CMD_CS = (0x2 << 11),
95 CRQB_CMD_LAST = (1 << 15),
96
97 CRPB_FLAG_STATUS_SHIFT = 8,
98
99 EPRD_FLAG_END_OF_TBL = (1 << 31),
100
Brett Russ20f733e2005-09-01 18:26:17 -0400101 /* PCI interface registers */
102
Brett Russ31961942005-09-30 01:36:00 -0400103 PCI_COMMAND_OFS = 0xc00,
104
Brett Russ20f733e2005-09-01 18:26:17 -0400105 PCI_MAIN_CMD_STS_OFS = 0xd30,
106 STOP_PCI_MASTER = (1 << 2),
107 PCI_MASTER_EMPTY = (1 << 3),
108 GLOB_SFT_RST = (1 << 4),
109
Jeff Garzik522479f2005-11-12 22:14:02 -0500110 MV_PCI_MODE = 0xd00,
111 MV_PCI_EXP_ROM_BAR_CTL = 0xd2c,
112 MV_PCI_DISC_TIMER = 0xd04,
113 MV_PCI_MSI_TRIGGER = 0xc38,
114 MV_PCI_SERR_MASK = 0xc28,
115 MV_PCI_XBAR_TMOUT = 0x1d04,
116 MV_PCI_ERR_LOW_ADDRESS = 0x1d40,
117 MV_PCI_ERR_HIGH_ADDRESS = 0x1d44,
118 MV_PCI_ERR_ATTRIBUTE = 0x1d48,
119 MV_PCI_ERR_COMMAND = 0x1d50,
120
121 PCI_IRQ_CAUSE_OFS = 0x1d58,
122 PCI_IRQ_MASK_OFS = 0x1d5c,
Brett Russ20f733e2005-09-01 18:26:17 -0400123 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
124
125 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
126 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
127 PORT0_ERR = (1 << 0), /* shift by port # */
128 PORT0_DONE = (1 << 1), /* shift by port # */
129 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
130 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
131 PCI_ERR = (1 << 18),
132 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
133 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
134 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
135 GPIO_INT = (1 << 22),
136 SELF_INT = (1 << 23),
137 TWSI_INT = (1 << 24),
138 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
Jeff Garzik8b260242005-11-12 12:32:50 -0500139 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
Brett Russ20f733e2005-09-01 18:26:17 -0400140 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
141 HC_MAIN_RSVD),
142
143 /* SATAHC registers */
144 HC_CFG_OFS = 0,
145
146 HC_IRQ_CAUSE_OFS = 0x14,
Brett Russ31961942005-09-30 01:36:00 -0400147 CRPB_DMA_DONE = (1 << 0), /* shift by port # */
Brett Russ20f733e2005-09-01 18:26:17 -0400148 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
149 DEV_IRQ = (1 << 8), /* shift by port # */
150
151 /* Shadow block registers */
Brett Russ31961942005-09-30 01:36:00 -0400152 SHD_BLK_OFS = 0x100,
153 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
Brett Russ20f733e2005-09-01 18:26:17 -0400154
155 /* SATA registers */
156 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
157 SATA_ACTIVE_OFS = 0x350,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500158 PHY_MODE3 = 0x310,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500159 PHY_MODE4 = 0x314,
160 PHY_MODE2 = 0x330,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500161 MV5_PHY_MODE = 0x74,
162 MV5_LT_MODE = 0x30,
163 MV5_PHY_CTL = 0x0C,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500164 SATA_INTERFACE_CTL = 0x050,
165
166 MV_M2_PREAMP_MASK = 0x7e0,
Brett Russ20f733e2005-09-01 18:26:17 -0400167
168 /* Port registers */
169 EDMA_CFG_OFS = 0,
Brett Russ31961942005-09-30 01:36:00 -0400170 EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */
171 EDMA_CFG_NCQ = (1 << 5),
172 EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
173 EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
174 EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
Brett Russ20f733e2005-09-01 18:26:17 -0400175
176 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
177 EDMA_ERR_IRQ_MASK_OFS = 0xc,
178 EDMA_ERR_D_PAR = (1 << 0),
179 EDMA_ERR_PRD_PAR = (1 << 1),
180 EDMA_ERR_DEV = (1 << 2),
181 EDMA_ERR_DEV_DCON = (1 << 3),
182 EDMA_ERR_DEV_CON = (1 << 4),
183 EDMA_ERR_SERR = (1 << 5),
184 EDMA_ERR_SELF_DIS = (1 << 7),
185 EDMA_ERR_BIST_ASYNC = (1 << 8),
186 EDMA_ERR_CRBQ_PAR = (1 << 9),
187 EDMA_ERR_CRPB_PAR = (1 << 10),
188 EDMA_ERR_INTRL_PAR = (1 << 11),
189 EDMA_ERR_IORDY = (1 << 12),
190 EDMA_ERR_LNK_CTRL_RX = (0xf << 13),
191 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
192 EDMA_ERR_LNK_DATA_RX = (0xf << 17),
193 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21),
194 EDMA_ERR_LNK_DATA_TX = (0x1f << 26),
195 EDMA_ERR_TRANS_PROTO = (1 << 31),
Jeff Garzik8b260242005-11-12 12:32:50 -0500196 EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
Brett Russ20f733e2005-09-01 18:26:17 -0400197 EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR |
198 EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR |
Jeff Garzik8b260242005-11-12 12:32:50 -0500199 EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 |
Brett Russ20f733e2005-09-01 18:26:17 -0400200 EDMA_ERR_LNK_DATA_RX |
Jeff Garzik8b260242005-11-12 12:32:50 -0500201 EDMA_ERR_LNK_DATA_TX |
Brett Russ20f733e2005-09-01 18:26:17 -0400202 EDMA_ERR_TRANS_PROTO),
203
Brett Russ31961942005-09-30 01:36:00 -0400204 EDMA_REQ_Q_BASE_HI_OFS = 0x10,
205 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400206
207 EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
208 EDMA_REQ_Q_PTR_SHIFT = 5,
209
210 EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
211 EDMA_RSP_Q_IN_PTR_OFS = 0x20,
212 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400213 EDMA_RSP_Q_PTR_SHIFT = 3,
214
Brett Russ20f733e2005-09-01 18:26:17 -0400215 EDMA_CMD_OFS = 0x28,
216 EDMA_EN = (1 << 0),
217 EDMA_DS = (1 << 1),
218 ATA_RST = (1 << 2),
219
Jeff Garzikc9d39132005-11-13 17:47:51 -0500220 EDMA_IORDY_TMOUT = 0x34,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500221 EDMA_ARB_CFG = 0x38,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500222
Brett Russ31961942005-09-30 01:36:00 -0400223 /* Host private flags (hp_flags) */
224 MV_HP_FLAG_MSI = (1 << 0),
Jeff Garzik47c2b672005-11-12 21:13:17 -0500225 MV_HP_ERRATA_50XXB0 = (1 << 1),
226 MV_HP_ERRATA_50XXB2 = (1 << 2),
227 MV_HP_ERRATA_60X1B2 = (1 << 3),
228 MV_HP_ERRATA_60X1C0 = (1 << 4),
229 MV_HP_50XX = (1 << 5),
Brett Russ20f733e2005-09-01 18:26:17 -0400230
Brett Russ31961942005-09-30 01:36:00 -0400231 /* Port private flags (pp_flags) */
232 MV_PP_FLAG_EDMA_EN = (1 << 0),
233 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1),
234};
235
Jeff Garzikc9d39132005-11-13 17:47:51 -0500236#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500237#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0)
238
Jeff Garzik095fec82005-11-12 09:50:49 -0500239enum {
240 /* Our DMA boundary is determined by an ePRD being unable to handle
241 * anything larger than 64KB
242 */
243 MV_DMA_BOUNDARY = 0xffffU,
244
245 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
246
247 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
248};
249
Jeff Garzik522479f2005-11-12 22:14:02 -0500250enum chip_type {
251 chip_504x,
252 chip_508x,
253 chip_5080,
254 chip_604x,
255 chip_608x,
256};
257
Brett Russ31961942005-09-30 01:36:00 -0400258/* Command ReQuest Block: 32B */
259struct mv_crqb {
260 u32 sg_addr;
261 u32 sg_addr_hi;
262 u16 ctrl_flags;
263 u16 ata_cmd[11];
264};
265
266/* Command ResPonse Block: 8B */
267struct mv_crpb {
268 u16 id;
269 u16 flags;
270 u32 tmstmp;
271};
272
273/* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
274struct mv_sg {
275 u32 addr;
276 u32 flags_size;
277 u32 addr_hi;
278 u32 reserved;
Brett Russ20f733e2005-09-01 18:26:17 -0400279};
280
281struct mv_port_priv {
Brett Russ31961942005-09-30 01:36:00 -0400282 struct mv_crqb *crqb;
283 dma_addr_t crqb_dma;
284 struct mv_crpb *crpb;
285 dma_addr_t crpb_dma;
286 struct mv_sg *sg_tbl;
287 dma_addr_t sg_tbl_dma;
Brett Russ20f733e2005-09-01 18:26:17 -0400288
Brett Russ31961942005-09-30 01:36:00 -0400289 unsigned req_producer; /* cp of req_in_ptr */
290 unsigned rsp_consumer; /* cp of rsp_out_ptr */
291 u32 pp_flags;
Brett Russ20f733e2005-09-01 18:26:17 -0400292};
293
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500294struct mv_port_signal {
295 u32 amps;
296 u32 pre;
297};
298
Jeff Garzik47c2b672005-11-12 21:13:17 -0500299struct mv_host_priv;
300struct mv_hw_ops {
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500301 void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
302 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500303 void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio);
304 void (*read_preamp)(struct mv_host_priv *hpriv, int idx,
305 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500306 int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio,
307 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500308 void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio);
309 void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500310};
311
Brett Russ20f733e2005-09-01 18:26:17 -0400312struct mv_host_priv {
Brett Russ31961942005-09-30 01:36:00 -0400313 u32 hp_flags;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500314 struct mv_port_signal signal[8];
Jeff Garzik47c2b672005-11-12 21:13:17 -0500315 const struct mv_hw_ops *ops;
Brett Russ20f733e2005-09-01 18:26:17 -0400316};
317
318static void mv_irq_clear(struct ata_port *ap);
319static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
320static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500321static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
322static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Brett Russ20f733e2005-09-01 18:26:17 -0400323static void mv_phy_reset(struct ata_port *ap);
Jeff Garzik22374672005-11-17 10:59:48 -0500324static void __mv_phy_reset(struct ata_port *ap, int can_sleep);
Brett Russ31961942005-09-30 01:36:00 -0400325static void mv_host_stop(struct ata_host_set *host_set);
326static int mv_port_start(struct ata_port *ap);
327static void mv_port_stop(struct ata_port *ap);
328static void mv_qc_prep(struct ata_queued_cmd *qc);
329static int mv_qc_issue(struct ata_queued_cmd *qc);
Brett Russ20f733e2005-09-01 18:26:17 -0400330static irqreturn_t mv_interrupt(int irq, void *dev_instance,
331 struct pt_regs *regs);
Brett Russ31961942005-09-30 01:36:00 -0400332static void mv_eng_timeout(struct ata_port *ap);
Brett Russ20f733e2005-09-01 18:26:17 -0400333static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
334
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500335static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
336 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500337static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
338static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
339 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500340static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
341 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500342static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
343static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500344
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500345static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
346 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500347static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
348static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
349 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500350static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
351 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500352static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
353static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500354static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
355 unsigned int port_no);
356static void mv_stop_and_reset(struct ata_port *ap);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500357
Jeff Garzik193515d2005-11-07 00:59:37 -0500358static struct scsi_host_template mv_sht = {
Brett Russ20f733e2005-09-01 18:26:17 -0400359 .module = THIS_MODULE,
360 .name = DRV_NAME,
361 .ioctl = ata_scsi_ioctl,
362 .queuecommand = ata_scsi_queuecmd,
363 .eh_strategy_handler = ata_scsi_error,
Brett Russ31961942005-09-30 01:36:00 -0400364 .can_queue = MV_USE_Q_DEPTH,
Brett Russ20f733e2005-09-01 18:26:17 -0400365 .this_id = ATA_SHT_THIS_ID,
Jeff Garzik22374672005-11-17 10:59:48 -0500366 .sg_tablesize = MV_MAX_SG_CT / 2,
Brett Russ20f733e2005-09-01 18:26:17 -0400367 .max_sectors = ATA_MAX_SECTORS,
368 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
369 .emulated = ATA_SHT_EMULATED,
Brett Russ31961942005-09-30 01:36:00 -0400370 .use_clustering = ATA_SHT_USE_CLUSTERING,
Brett Russ20f733e2005-09-01 18:26:17 -0400371 .proc_name = DRV_NAME,
372 .dma_boundary = MV_DMA_BOUNDARY,
373 .slave_configure = ata_scsi_slave_config,
374 .bios_param = ata_std_bios_param,
375 .ordered_flush = 1,
376};
377
Jeff Garzikc9d39132005-11-13 17:47:51 -0500378static const struct ata_port_operations mv5_ops = {
379 .port_disable = ata_port_disable,
380
381 .tf_load = ata_tf_load,
382 .tf_read = ata_tf_read,
383 .check_status = ata_check_status,
384 .exec_command = ata_exec_command,
385 .dev_select = ata_std_dev_select,
386
387 .phy_reset = mv_phy_reset,
388
389 .qc_prep = mv_qc_prep,
390 .qc_issue = mv_qc_issue,
391
392 .eng_timeout = mv_eng_timeout,
393
394 .irq_handler = mv_interrupt,
395 .irq_clear = mv_irq_clear,
396
397 .scr_read = mv5_scr_read,
398 .scr_write = mv5_scr_write,
399
400 .port_start = mv_port_start,
401 .port_stop = mv_port_stop,
402 .host_stop = mv_host_stop,
403};
404
405static const struct ata_port_operations mv6_ops = {
Brett Russ20f733e2005-09-01 18:26:17 -0400406 .port_disable = ata_port_disable,
407
408 .tf_load = ata_tf_load,
409 .tf_read = ata_tf_read,
410 .check_status = ata_check_status,
411 .exec_command = ata_exec_command,
412 .dev_select = ata_std_dev_select,
413
414 .phy_reset = mv_phy_reset,
415
Brett Russ31961942005-09-30 01:36:00 -0400416 .qc_prep = mv_qc_prep,
417 .qc_issue = mv_qc_issue,
Brett Russ20f733e2005-09-01 18:26:17 -0400418
Brett Russ31961942005-09-30 01:36:00 -0400419 .eng_timeout = mv_eng_timeout,
Brett Russ20f733e2005-09-01 18:26:17 -0400420
421 .irq_handler = mv_interrupt,
422 .irq_clear = mv_irq_clear,
423
424 .scr_read = mv_scr_read,
425 .scr_write = mv_scr_write,
426
Brett Russ31961942005-09-30 01:36:00 -0400427 .port_start = mv_port_start,
428 .port_stop = mv_port_stop,
429 .host_stop = mv_host_stop,
Brett Russ20f733e2005-09-01 18:26:17 -0400430};
431
432static struct ata_port_info mv_port_info[] = {
433 { /* chip_504x */
434 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400435 .host_flags = MV_COMMON_FLAGS,
436 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500437 .udma_mask = 0x7f, /* udma0-6 */
438 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400439 },
440 { /* chip_508x */
441 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400442 .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
443 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500444 .udma_mask = 0x7f, /* udma0-6 */
445 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400446 },
Jeff Garzik47c2b672005-11-12 21:13:17 -0500447 { /* chip_5080 */
448 .sht = &mv_sht,
449 .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
450 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500451 .udma_mask = 0x7f, /* udma0-6 */
452 .port_ops = &mv5_ops,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500453 },
Brett Russ20f733e2005-09-01 18:26:17 -0400454 { /* chip_604x */
455 .sht = &mv_sht,
Brett Russ31961942005-09-30 01:36:00 -0400456 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
457 .pio_mask = 0x1f, /* pio0-4 */
458 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500459 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400460 },
461 { /* chip_608x */
462 .sht = &mv_sht,
Jeff Garzik8b260242005-11-12 12:32:50 -0500463 .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
Brett Russ31961942005-09-30 01:36:00 -0400464 MV_FLAG_DUAL_HC),
465 .pio_mask = 0x1f, /* pio0-4 */
466 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500467 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400468 },
469};
470
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500471static const struct pci_device_id mv_pci_tbl[] = {
Brett Russ20f733e2005-09-01 18:26:17 -0400472 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5040), 0, 0, chip_504x},
473 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5041), 0, 0, chip_504x},
Jeff Garzik47c2b672005-11-12 21:13:17 -0500474 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5080), 0, 0, chip_5080},
Brett Russ20f733e2005-09-01 18:26:17 -0400475 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5081), 0, 0, chip_508x},
476
477 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x},
478 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6041), 0, 0, chip_604x},
479 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6080), 0, 0, chip_608x},
480 {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6081), 0, 0, chip_608x},
Jeff Garzik29179532005-11-11 08:08:03 -0500481
482 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x0241), 0, 0, chip_604x},
Brett Russ20f733e2005-09-01 18:26:17 -0400483 {} /* terminate list */
484};
485
486static struct pci_driver mv_pci_driver = {
487 .name = DRV_NAME,
488 .id_table = mv_pci_tbl,
489 .probe = mv_init_one,
490 .remove = ata_pci_remove_one,
491};
492
Jeff Garzik47c2b672005-11-12 21:13:17 -0500493static const struct mv_hw_ops mv5xxx_ops = {
494 .phy_errata = mv5_phy_errata,
495 .enable_leds = mv5_enable_leds,
496 .read_preamp = mv5_read_preamp,
497 .reset_hc = mv5_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500498 .reset_flash = mv5_reset_flash,
499 .reset_bus = mv5_reset_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500500};
501
502static const struct mv_hw_ops mv6xxx_ops = {
503 .phy_errata = mv6_phy_errata,
504 .enable_leds = mv6_enable_leds,
505 .read_preamp = mv6_read_preamp,
506 .reset_hc = mv6_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500507 .reset_flash = mv6_reset_flash,
508 .reset_bus = mv_reset_pci_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500509};
510
Brett Russ20f733e2005-09-01 18:26:17 -0400511/*
512 * Functions
513 */
514
515static inline void writelfl(unsigned long data, void __iomem *addr)
516{
517 writel(data, addr);
518 (void) readl(addr); /* flush to avoid PCI posted write */
519}
520
Brett Russ20f733e2005-09-01 18:26:17 -0400521static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
522{
523 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
524}
525
Jeff Garzikc9d39132005-11-13 17:47:51 -0500526static inline unsigned int mv_hc_from_port(unsigned int port)
527{
528 return port >> MV_PORT_HC_SHIFT;
529}
530
531static inline unsigned int mv_hardport_from_port(unsigned int port)
532{
533 return port & MV_PORT_MASK;
534}
535
536static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
537 unsigned int port)
538{
539 return mv_hc_base(base, mv_hc_from_port(port));
540}
541
Brett Russ20f733e2005-09-01 18:26:17 -0400542static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
543{
Jeff Garzikc9d39132005-11-13 17:47:51 -0500544 return mv_hc_base_from_port(base, port) +
Jeff Garzik8b260242005-11-12 12:32:50 -0500545 MV_SATAHC_ARBTR_REG_SZ +
Jeff Garzikc9d39132005-11-13 17:47:51 -0500546 (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
Brett Russ20f733e2005-09-01 18:26:17 -0400547}
548
549static inline void __iomem *mv_ap_base(struct ata_port *ap)
550{
551 return mv_port_base(ap->host_set->mmio_base, ap->port_no);
552}
553
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500554static inline int mv_get_hc_count(unsigned long host_flags)
Brett Russ20f733e2005-09-01 18:26:17 -0400555{
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500556 return ((host_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
Brett Russ20f733e2005-09-01 18:26:17 -0400557}
558
559static void mv_irq_clear(struct ata_port *ap)
560{
561}
562
Brett Russ05b308e2005-10-05 17:08:53 -0400563/**
564 * mv_start_dma - Enable eDMA engine
565 * @base: port base address
566 * @pp: port private data
567 *
568 * Verify the local cache of the eDMA state is accurate with an
569 * assert.
570 *
571 * LOCKING:
572 * Inherited from caller.
573 */
Brett Russafb0edd2005-10-05 17:08:42 -0400574static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
Brett Russ31961942005-09-30 01:36:00 -0400575{
Brett Russafb0edd2005-10-05 17:08:42 -0400576 if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) {
577 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
578 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
579 }
580 assert(EDMA_EN & readl(base + EDMA_CMD_OFS));
Brett Russ31961942005-09-30 01:36:00 -0400581}
582
Brett Russ05b308e2005-10-05 17:08:53 -0400583/**
584 * mv_stop_dma - Disable eDMA engine
585 * @ap: ATA channel to manipulate
586 *
587 * Verify the local cache of the eDMA state is accurate with an
588 * assert.
589 *
590 * LOCKING:
591 * Inherited from caller.
592 */
Brett Russ31961942005-09-30 01:36:00 -0400593static void mv_stop_dma(struct ata_port *ap)
594{
595 void __iomem *port_mmio = mv_ap_base(ap);
596 struct mv_port_priv *pp = ap->private_data;
Brett Russ31961942005-09-30 01:36:00 -0400597 u32 reg;
598 int i;
599
Brett Russafb0edd2005-10-05 17:08:42 -0400600 if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) {
601 /* Disable EDMA if active. The disable bit auto clears.
Brett Russ31961942005-09-30 01:36:00 -0400602 */
Brett Russ31961942005-09-30 01:36:00 -0400603 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
604 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
Brett Russafb0edd2005-10-05 17:08:42 -0400605 } else {
606 assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)));
607 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500608
Brett Russ31961942005-09-30 01:36:00 -0400609 /* now properly wait for the eDMA to stop */
610 for (i = 1000; i > 0; i--) {
611 reg = readl(port_mmio + EDMA_CMD_OFS);
612 if (!(EDMA_EN & reg)) {
613 break;
614 }
615 udelay(100);
616 }
617
Brett Russ31961942005-09-30 01:36:00 -0400618 if (EDMA_EN & reg) {
619 printk(KERN_ERR "ata%u: Unable to stop eDMA\n", ap->id);
Brett Russafb0edd2005-10-05 17:08:42 -0400620 /* FIXME: Consider doing a reset here to recover */
Brett Russ31961942005-09-30 01:36:00 -0400621 }
622}
623
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400624#ifdef ATA_DEBUG
Brett Russ31961942005-09-30 01:36:00 -0400625static void mv_dump_mem(void __iomem *start, unsigned bytes)
626{
Brett Russ31961942005-09-30 01:36:00 -0400627 int b, w;
628 for (b = 0; b < bytes; ) {
629 DPRINTK("%p: ", start + b);
630 for (w = 0; b < bytes && w < 4; w++) {
631 printk("%08x ",readl(start + b));
632 b += sizeof(u32);
633 }
634 printk("\n");
635 }
Brett Russ31961942005-09-30 01:36:00 -0400636}
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400637#endif
638
Brett Russ31961942005-09-30 01:36:00 -0400639static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
640{
641#ifdef ATA_DEBUG
642 int b, w;
643 u32 dw;
644 for (b = 0; b < bytes; ) {
645 DPRINTK("%02x: ", b);
646 for (w = 0; b < bytes && w < 4; w++) {
647 (void) pci_read_config_dword(pdev,b,&dw);
648 printk("%08x ",dw);
649 b += sizeof(u32);
650 }
651 printk("\n");
652 }
653#endif
654}
655static void mv_dump_all_regs(void __iomem *mmio_base, int port,
656 struct pci_dev *pdev)
657{
658#ifdef ATA_DEBUG
Jeff Garzik8b260242005-11-12 12:32:50 -0500659 void __iomem *hc_base = mv_hc_base(mmio_base,
Brett Russ31961942005-09-30 01:36:00 -0400660 port >> MV_PORT_HC_SHIFT);
661 void __iomem *port_base;
662 int start_port, num_ports, p, start_hc, num_hcs, hc;
663
664 if (0 > port) {
665 start_hc = start_port = 0;
666 num_ports = 8; /* shld be benign for 4 port devs */
667 num_hcs = 2;
668 } else {
669 start_hc = port >> MV_PORT_HC_SHIFT;
670 start_port = port;
671 num_ports = num_hcs = 1;
672 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500673 DPRINTK("All registers for port(s) %u-%u:\n", start_port,
Brett Russ31961942005-09-30 01:36:00 -0400674 num_ports > 1 ? num_ports - 1 : start_port);
675
676 if (NULL != pdev) {
677 DPRINTK("PCI config space regs:\n");
678 mv_dump_pci_cfg(pdev, 0x68);
679 }
680 DPRINTK("PCI regs:\n");
681 mv_dump_mem(mmio_base+0xc00, 0x3c);
682 mv_dump_mem(mmio_base+0xd00, 0x34);
683 mv_dump_mem(mmio_base+0xf00, 0x4);
684 mv_dump_mem(mmio_base+0x1d00, 0x6c);
685 for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
686 hc_base = mv_hc_base(mmio_base, port >> MV_PORT_HC_SHIFT);
687 DPRINTK("HC regs (HC %i):\n", hc);
688 mv_dump_mem(hc_base, 0x1c);
689 }
690 for (p = start_port; p < start_port + num_ports; p++) {
691 port_base = mv_port_base(mmio_base, p);
692 DPRINTK("EDMA regs (port %i):\n",p);
693 mv_dump_mem(port_base, 0x54);
694 DPRINTK("SATA regs (port %i):\n",p);
695 mv_dump_mem(port_base+0x300, 0x60);
696 }
697#endif
698}
699
Brett Russ20f733e2005-09-01 18:26:17 -0400700static unsigned int mv_scr_offset(unsigned int sc_reg_in)
701{
702 unsigned int ofs;
703
704 switch (sc_reg_in) {
705 case SCR_STATUS:
706 case SCR_CONTROL:
707 case SCR_ERROR:
708 ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
709 break;
710 case SCR_ACTIVE:
711 ofs = SATA_ACTIVE_OFS; /* active is not with the others */
712 break;
713 default:
714 ofs = 0xffffffffU;
715 break;
716 }
717 return ofs;
718}
719
720static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
721{
722 unsigned int ofs = mv_scr_offset(sc_reg_in);
723
724 if (0xffffffffU != ofs) {
725 return readl(mv_ap_base(ap) + ofs);
726 } else {
727 return (u32) ofs;
728 }
729}
730
731static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
732{
733 unsigned int ofs = mv_scr_offset(sc_reg_in);
734
735 if (0xffffffffU != ofs) {
736 writelfl(val, mv_ap_base(ap) + ofs);
737 }
738}
739
Brett Russ05b308e2005-10-05 17:08:53 -0400740/**
741 * mv_host_stop - Host specific cleanup/stop routine.
742 * @host_set: host data structure
743 *
744 * Disable ints, cleanup host memory, call general purpose
745 * host_stop.
746 *
747 * LOCKING:
748 * Inherited from caller.
749 */
Brett Russ31961942005-09-30 01:36:00 -0400750static void mv_host_stop(struct ata_host_set *host_set)
751{
752 struct mv_host_priv *hpriv = host_set->private_data;
753 struct pci_dev *pdev = to_pci_dev(host_set->dev);
754
755 if (hpriv->hp_flags & MV_HP_FLAG_MSI) {
756 pci_disable_msi(pdev);
757 } else {
758 pci_intx(pdev, 0);
759 }
760 kfree(hpriv);
761 ata_host_stop(host_set);
762}
763
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500764static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev)
765{
766 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma);
767}
768
Brett Russ05b308e2005-10-05 17:08:53 -0400769/**
770 * mv_port_start - Port specific init/start routine.
771 * @ap: ATA channel to manipulate
772 *
773 * Allocate and point to DMA memory, init port private memory,
774 * zero indices.
775 *
776 * LOCKING:
777 * Inherited from caller.
778 */
Brett Russ31961942005-09-30 01:36:00 -0400779static int mv_port_start(struct ata_port *ap)
780{
781 struct device *dev = ap->host_set->dev;
782 struct mv_port_priv *pp;
783 void __iomem *port_mmio = mv_ap_base(ap);
784 void *mem;
785 dma_addr_t mem_dma;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500786 int rc = -ENOMEM;
Brett Russ31961942005-09-30 01:36:00 -0400787
788 pp = kmalloc(sizeof(*pp), GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500789 if (!pp)
790 goto err_out;
Brett Russ31961942005-09-30 01:36:00 -0400791 memset(pp, 0, sizeof(*pp));
792
Jeff Garzik8b260242005-11-12 12:32:50 -0500793 mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
Brett Russ31961942005-09-30 01:36:00 -0400794 GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500795 if (!mem)
796 goto err_out_pp;
Brett Russ31961942005-09-30 01:36:00 -0400797 memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
798
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500799 rc = ata_pad_alloc(ap, dev);
800 if (rc)
801 goto err_out_priv;
802
Jeff Garzik8b260242005-11-12 12:32:50 -0500803 /* First item in chunk of DMA memory:
Brett Russ31961942005-09-30 01:36:00 -0400804 * 32-slot command request table (CRQB), 32 bytes each in size
805 */
806 pp->crqb = mem;
807 pp->crqb_dma = mem_dma;
808 mem += MV_CRQB_Q_SZ;
809 mem_dma += MV_CRQB_Q_SZ;
810
Jeff Garzik8b260242005-11-12 12:32:50 -0500811 /* Second item:
Brett Russ31961942005-09-30 01:36:00 -0400812 * 32-slot command response table (CRPB), 8 bytes each in size
813 */
814 pp->crpb = mem;
815 pp->crpb_dma = mem_dma;
816 mem += MV_CRPB_Q_SZ;
817 mem_dma += MV_CRPB_Q_SZ;
818
819 /* Third item:
820 * Table of scatter-gather descriptors (ePRD), 16 bytes each
821 */
822 pp->sg_tbl = mem;
823 pp->sg_tbl_dma = mem_dma;
824
Jeff Garzik8b260242005-11-12 12:32:50 -0500825 writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT |
Brett Russ31961942005-09-30 01:36:00 -0400826 EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS);
827
828 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
Jeff Garzik8b260242005-11-12 12:32:50 -0500829 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400830 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
831
832 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
833 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
834
835 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
Jeff Garzik8b260242005-11-12 12:32:50 -0500836 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400837 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
838
839 pp->req_producer = pp->rsp_consumer = 0;
840
841 /* Don't turn on EDMA here...do it before DMA commands only. Else
842 * we'll be unable to send non-data, PIO, etc due to restricted access
843 * to shadow regs.
844 */
845 ap->private_data = pp;
846 return 0;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500847
848err_out_priv:
849 mv_priv_free(pp, dev);
850err_out_pp:
851 kfree(pp);
852err_out:
853 return rc;
Brett Russ31961942005-09-30 01:36:00 -0400854}
855
Brett Russ05b308e2005-10-05 17:08:53 -0400856/**
857 * mv_port_stop - Port specific cleanup/stop routine.
858 * @ap: ATA channel to manipulate
859 *
860 * Stop DMA, cleanup port memory.
861 *
862 * LOCKING:
863 * This routine uses the host_set lock to protect the DMA stop.
864 */
Brett Russ31961942005-09-30 01:36:00 -0400865static void mv_port_stop(struct ata_port *ap)
866{
867 struct device *dev = ap->host_set->dev;
868 struct mv_port_priv *pp = ap->private_data;
Brett Russafb0edd2005-10-05 17:08:42 -0400869 unsigned long flags;
Brett Russ31961942005-09-30 01:36:00 -0400870
Brett Russafb0edd2005-10-05 17:08:42 -0400871 spin_lock_irqsave(&ap->host_set->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400872 mv_stop_dma(ap);
Brett Russafb0edd2005-10-05 17:08:42 -0400873 spin_unlock_irqrestore(&ap->host_set->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400874
875 ap->private_data = NULL;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500876 ata_pad_free(ap, dev);
877 mv_priv_free(pp, dev);
Brett Russ31961942005-09-30 01:36:00 -0400878 kfree(pp);
879}
880
Brett Russ05b308e2005-10-05 17:08:53 -0400881/**
882 * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
883 * @qc: queued command whose SG list to source from
884 *
885 * Populate the SG list and mark the last entry.
886 *
887 * LOCKING:
888 * Inherited from caller.
889 */
Brett Russ31961942005-09-30 01:36:00 -0400890static void mv_fill_sg(struct ata_queued_cmd *qc)
891{
892 struct mv_port_priv *pp = qc->ap->private_data;
Jeff Garzik972c26b2005-10-18 22:14:54 -0400893 unsigned int i = 0;
894 struct scatterlist *sg;
Brett Russ31961942005-09-30 01:36:00 -0400895
Jeff Garzik972c26b2005-10-18 22:14:54 -0400896 ata_for_each_sg(sg, qc) {
Brett Russ31961942005-09-30 01:36:00 -0400897 dma_addr_t addr;
Jeff Garzik22374672005-11-17 10:59:48 -0500898 u32 sg_len, len, offset;
Brett Russ31961942005-09-30 01:36:00 -0400899
Jeff Garzik972c26b2005-10-18 22:14:54 -0400900 addr = sg_dma_address(sg);
901 sg_len = sg_dma_len(sg);
Brett Russ31961942005-09-30 01:36:00 -0400902
Jeff Garzik22374672005-11-17 10:59:48 -0500903 while (sg_len) {
904 offset = addr & MV_DMA_BOUNDARY;
905 len = sg_len;
906 if ((offset + sg_len) > 0x10000)
907 len = 0x10000 - offset;
Jeff Garzik972c26b2005-10-18 22:14:54 -0400908
Jeff Garzik22374672005-11-17 10:59:48 -0500909 pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
910 pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
911 pp->sg_tbl[i].flags_size = cpu_to_le32(len);
912
913 sg_len -= len;
914 addr += len;
915
916 if (!sg_len && ata_sg_is_last(sg, qc))
917 pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
918
919 i++;
920 }
Brett Russ31961942005-09-30 01:36:00 -0400921 }
922}
923
924static inline unsigned mv_inc_q_index(unsigned *index)
925{
926 *index = (*index + 1) & MV_MAX_Q_DEPTH_MASK;
927 return *index;
928}
929
930static inline void mv_crqb_pack_cmd(u16 *cmdw, u8 data, u8 addr, unsigned last)
931{
932 *cmdw = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
933 (last ? CRQB_CMD_LAST : 0);
934}
935
Brett Russ05b308e2005-10-05 17:08:53 -0400936/**
937 * mv_qc_prep - Host specific command preparation.
938 * @qc: queued command to prepare
939 *
940 * This routine simply redirects to the general purpose routine
941 * if command is not DMA. Else, it handles prep of the CRQB
942 * (command request block), does some sanity checking, and calls
943 * the SG load routine.
944 *
945 * LOCKING:
946 * Inherited from caller.
947 */
Brett Russ31961942005-09-30 01:36:00 -0400948static void mv_qc_prep(struct ata_queued_cmd *qc)
949{
950 struct ata_port *ap = qc->ap;
951 struct mv_port_priv *pp = ap->private_data;
952 u16 *cw;
953 struct ata_taskfile *tf;
954 u16 flags = 0;
955
956 if (ATA_PROT_DMA != qc->tf.protocol) {
957 return;
Brett Russ20f733e2005-09-01 18:26:17 -0400958 }
959
Brett Russ31961942005-09-30 01:36:00 -0400960 /* the req producer index should be the same as we remember it */
Jeff Garzik8b260242005-11-12 12:32:50 -0500961 assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >>
Brett Russ31961942005-09-30 01:36:00 -0400962 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
963 pp->req_producer);
964
965 /* Fill in command request block
966 */
967 if (!(qc->tf.flags & ATA_TFLAG_WRITE)) {
968 flags |= CRQB_FLAG_READ;
969 }
970 assert(MV_MAX_Q_DEPTH > qc->tag);
971 flags |= qc->tag << CRQB_TAG_SHIFT;
972
Jeff Garzik8b260242005-11-12 12:32:50 -0500973 pp->crqb[pp->req_producer].sg_addr =
Brett Russ31961942005-09-30 01:36:00 -0400974 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
Jeff Garzik8b260242005-11-12 12:32:50 -0500975 pp->crqb[pp->req_producer].sg_addr_hi =
Brett Russ31961942005-09-30 01:36:00 -0400976 cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
977 pp->crqb[pp->req_producer].ctrl_flags = cpu_to_le16(flags);
978
979 cw = &pp->crqb[pp->req_producer].ata_cmd[0];
980 tf = &qc->tf;
981
982 /* Sadly, the CRQB cannot accomodate all registers--there are
983 * only 11 bytes...so we must pick and choose required
984 * registers based on the command. So, we drop feature and
985 * hob_feature for [RW] DMA commands, but they are needed for
986 * NCQ. NCQ will drop hob_nsect.
987 */
988 switch (tf->command) {
989 case ATA_CMD_READ:
990 case ATA_CMD_READ_EXT:
991 case ATA_CMD_WRITE:
992 case ATA_CMD_WRITE_EXT:
993 mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
994 break;
995#ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */
996 case ATA_CMD_FPDMA_READ:
997 case ATA_CMD_FPDMA_WRITE:
Jeff Garzik8b260242005-11-12 12:32:50 -0500998 mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
Brett Russ31961942005-09-30 01:36:00 -0400999 mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
1000 break;
1001#endif /* FIXME: remove this line when NCQ added */
1002 default:
1003 /* The only other commands EDMA supports in non-queued and
1004 * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
1005 * of which are defined/used by Linux. If we get here, this
1006 * driver needs work.
1007 *
1008 * FIXME: modify libata to give qc_prep a return value and
1009 * return error here.
1010 */
1011 BUG_ON(tf->command);
1012 break;
1013 }
1014 mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
1015 mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
1016 mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
1017 mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
1018 mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
1019 mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
1020 mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
1021 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
1022 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
1023
1024 if (!(qc->flags & ATA_QCFLAG_DMAMAP)) {
1025 return;
1026 }
1027 mv_fill_sg(qc);
1028}
1029
Brett Russ05b308e2005-10-05 17:08:53 -04001030/**
1031 * mv_qc_issue - Initiate a command to the host
1032 * @qc: queued command to start
1033 *
1034 * This routine simply redirects to the general purpose routine
1035 * if command is not DMA. Else, it sanity checks our local
1036 * caches of the request producer/consumer indices then enables
1037 * DMA and bumps the request producer index.
1038 *
1039 * LOCKING:
1040 * Inherited from caller.
1041 */
Brett Russ31961942005-09-30 01:36:00 -04001042static int mv_qc_issue(struct ata_queued_cmd *qc)
1043{
1044 void __iomem *port_mmio = mv_ap_base(qc->ap);
1045 struct mv_port_priv *pp = qc->ap->private_data;
1046 u32 in_ptr;
1047
1048 if (ATA_PROT_DMA != qc->tf.protocol) {
1049 /* We're about to send a non-EDMA capable command to the
1050 * port. Turn off EDMA so there won't be problems accessing
1051 * shadow block, etc registers.
1052 */
1053 mv_stop_dma(qc->ap);
1054 return ata_qc_issue_prot(qc);
1055 }
1056
1057 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1058
1059 /* the req producer index should be the same as we remember it */
1060 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
1061 pp->req_producer);
1062 /* until we do queuing, the queue should be empty at this point */
1063 assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Jeff Garzik8b260242005-11-12 12:32:50 -05001064 ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >>
Brett Russ31961942005-09-30 01:36:00 -04001065 EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
1066
1067 mv_inc_q_index(&pp->req_producer); /* now incr producer index */
1068
Brett Russafb0edd2005-10-05 17:08:42 -04001069 mv_start_dma(port_mmio, pp);
Brett Russ31961942005-09-30 01:36:00 -04001070
1071 /* and write the request in pointer to kick the EDMA to life */
1072 in_ptr &= EDMA_REQ_Q_BASE_LO_MASK;
1073 in_ptr |= pp->req_producer << EDMA_REQ_Q_PTR_SHIFT;
1074 writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1075
1076 return 0;
1077}
1078
Brett Russ05b308e2005-10-05 17:08:53 -04001079/**
1080 * mv_get_crpb_status - get status from most recently completed cmd
1081 * @ap: ATA channel to manipulate
1082 *
1083 * This routine is for use when the port is in DMA mode, when it
1084 * will be using the CRPB (command response block) method of
1085 * returning command completion information. We assert indices
1086 * are good, grab status, and bump the response consumer index to
1087 * prove that we're up to date.
1088 *
1089 * LOCKING:
1090 * Inherited from caller.
1091 */
Brett Russ31961942005-09-30 01:36:00 -04001092static u8 mv_get_crpb_status(struct ata_port *ap)
1093{
1094 void __iomem *port_mmio = mv_ap_base(ap);
1095 struct mv_port_priv *pp = ap->private_data;
1096 u32 out_ptr;
1097
1098 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1099
1100 /* the response consumer index should be the same as we remember it */
Jeff Garzik8b260242005-11-12 12:32:50 -05001101 assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Brett Russ31961942005-09-30 01:36:00 -04001102 pp->rsp_consumer);
1103
1104 /* increment our consumer index... */
1105 pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer);
Jeff Garzik8b260242005-11-12 12:32:50 -05001106
Brett Russ31961942005-09-30 01:36:00 -04001107 /* and, until we do NCQ, there should only be 1 CRPB waiting */
Jeff Garzik8b260242005-11-12 12:32:50 -05001108 assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >>
1109 EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) ==
Brett Russ31961942005-09-30 01:36:00 -04001110 pp->rsp_consumer);
1111
1112 /* write out our inc'd consumer index so EDMA knows we're caught up */
1113 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
1114 out_ptr |= pp->rsp_consumer << EDMA_RSP_Q_PTR_SHIFT;
1115 writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1116
1117 /* Return ATA status register for completed CRPB */
1118 return (pp->crpb[pp->rsp_consumer].flags >> CRPB_FLAG_STATUS_SHIFT);
Brett Russ20f733e2005-09-01 18:26:17 -04001119}
1120
Brett Russ05b308e2005-10-05 17:08:53 -04001121/**
1122 * mv_err_intr - Handle error interrupts on the port
1123 * @ap: ATA channel to manipulate
1124 *
1125 * In most cases, just clear the interrupt and move on. However,
1126 * some cases require an eDMA reset, which is done right before
1127 * the COMRESET in mv_phy_reset(). The SERR case requires a
1128 * clear of pending errors in the SATA SERROR register. Finally,
1129 * if the port disabled DMA, update our cached copy to match.
1130 *
1131 * LOCKING:
1132 * Inherited from caller.
1133 */
Brett Russ20f733e2005-09-01 18:26:17 -04001134static void mv_err_intr(struct ata_port *ap)
1135{
Brett Russ31961942005-09-30 01:36:00 -04001136 void __iomem *port_mmio = mv_ap_base(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001137 u32 edma_err_cause, serr = 0;
1138
Brett Russ20f733e2005-09-01 18:26:17 -04001139 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1140
1141 if (EDMA_ERR_SERR & edma_err_cause) {
1142 serr = scr_read(ap, SCR_ERROR);
1143 scr_write_flush(ap, SCR_ERROR, serr);
1144 }
Brett Russafb0edd2005-10-05 17:08:42 -04001145 if (EDMA_ERR_SELF_DIS & edma_err_cause) {
1146 struct mv_port_priv *pp = ap->private_data;
1147 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1148 }
1149 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
1150 "SERR: 0x%08x\n", ap->id, edma_err_cause, serr);
Brett Russ20f733e2005-09-01 18:26:17 -04001151
1152 /* Clear EDMA now that SERR cleanup done */
1153 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1154
1155 /* check for fatal here and recover if needed */
1156 if (EDMA_ERR_FATAL & edma_err_cause) {
Jeff Garzikc9d39132005-11-13 17:47:51 -05001157 mv_stop_and_reset(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001158 }
1159}
1160
Brett Russ05b308e2005-10-05 17:08:53 -04001161/**
1162 * mv_host_intr - Handle all interrupts on the given host controller
1163 * @host_set: host specific structure
1164 * @relevant: port error bits relevant to this host controller
1165 * @hc: which host controller we're to look at
1166 *
1167 * Read then write clear the HC interrupt status then walk each
1168 * port connected to the HC and see if it needs servicing. Port
1169 * success ints are reported in the HC interrupt status reg, the
1170 * port error ints are reported in the higher level main
1171 * interrupt status register and thus are passed in via the
1172 * 'relevant' argument.
1173 *
1174 * LOCKING:
1175 * Inherited from caller.
1176 */
Brett Russ20f733e2005-09-01 18:26:17 -04001177static void mv_host_intr(struct ata_host_set *host_set, u32 relevant,
1178 unsigned int hc)
1179{
1180 void __iomem *mmio = host_set->mmio_base;
1181 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1182 struct ata_port *ap;
1183 struct ata_queued_cmd *qc;
1184 u32 hc_irq_cause;
Brett Russ31961942005-09-30 01:36:00 -04001185 int shift, port, port0, hard_port, handled;
Jeff Garzika7dac442005-10-30 04:44:42 -05001186 unsigned int err_mask;
Brett Russ31961942005-09-30 01:36:00 -04001187 u8 ata_status = 0;
Brett Russ20f733e2005-09-01 18:26:17 -04001188
1189 if (hc == 0) {
1190 port0 = 0;
1191 } else {
1192 port0 = MV_PORTS_PER_HC;
1193 }
1194
1195 /* we'll need the HC success int register in most cases */
1196 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
1197 if (hc_irq_cause) {
Brett Russ31961942005-09-30 01:36:00 -04001198 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001199 }
1200
1201 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1202 hc,relevant,hc_irq_cause);
1203
1204 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
1205 ap = host_set->ports[port];
1206 hard_port = port & MV_PORT_MASK; /* range 0-3 */
Brett Russ31961942005-09-30 01:36:00 -04001207 handled = 0; /* ensure ata_status is set if handled++ */
Brett Russ20f733e2005-09-01 18:26:17 -04001208
Brett Russ31961942005-09-30 01:36:00 -04001209 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {
1210 /* new CRPB on the queue; just one at a time until NCQ
1211 */
1212 ata_status = mv_get_crpb_status(ap);
1213 handled++;
1214 } else if ((DEV_IRQ << hard_port) & hc_irq_cause) {
1215 /* received ATA IRQ; read the status reg to clear INTRQ
Brett Russ20f733e2005-09-01 18:26:17 -04001216 */
1217 ata_status = readb((void __iomem *)
1218 ap->ioaddr.status_addr);
Brett Russ31961942005-09-30 01:36:00 -04001219 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001220 }
1221
Jeff Garzika7dac442005-10-30 04:44:42 -05001222 err_mask = ac_err_mask(ata_status);
1223
Brett Russ31961942005-09-30 01:36:00 -04001224 shift = port << 1; /* (port * 2) */
Brett Russ20f733e2005-09-01 18:26:17 -04001225 if (port >= MV_PORTS_PER_HC) {
1226 shift++; /* skip bit 8 in the HC Main IRQ reg */
1227 }
1228 if ((PORT0_ERR << shift) & relevant) {
1229 mv_err_intr(ap);
Jeff Garzika7dac442005-10-30 04:44:42 -05001230 err_mask |= AC_ERR_OTHER;
Brett Russ31961942005-09-30 01:36:00 -04001231 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001232 }
Jeff Garzik8b260242005-11-12 12:32:50 -05001233
Brett Russ31961942005-09-30 01:36:00 -04001234 if (handled && ap) {
Brett Russ20f733e2005-09-01 18:26:17 -04001235 qc = ata_qc_from_tag(ap, ap->active_tag);
1236 if (NULL != qc) {
1237 VPRINTK("port %u IRQ found for qc, "
1238 "ata_status 0x%x\n", port,ata_status);
Brett Russ20f733e2005-09-01 18:26:17 -04001239 /* mark qc status appropriately */
Jeff Garzika7dac442005-10-30 04:44:42 -05001240 ata_qc_complete(qc, err_mask);
Brett Russ20f733e2005-09-01 18:26:17 -04001241 }
1242 }
1243 }
1244 VPRINTK("EXIT\n");
1245}
1246
Brett Russ05b308e2005-10-05 17:08:53 -04001247/**
Jeff Garzik8b260242005-11-12 12:32:50 -05001248 * mv_interrupt -
Brett Russ05b308e2005-10-05 17:08:53 -04001249 * @irq: unused
1250 * @dev_instance: private data; in this case the host structure
1251 * @regs: unused
1252 *
1253 * Read the read only register to determine if any host
1254 * controllers have pending interrupts. If so, call lower level
1255 * routine to handle. Also check for PCI errors which are only
1256 * reported here.
1257 *
Jeff Garzik8b260242005-11-12 12:32:50 -05001258 * LOCKING:
Brett Russ05b308e2005-10-05 17:08:53 -04001259 * This routine holds the host_set lock while processing pending
1260 * interrupts.
1261 */
Brett Russ20f733e2005-09-01 18:26:17 -04001262static irqreturn_t mv_interrupt(int irq, void *dev_instance,
1263 struct pt_regs *regs)
1264{
1265 struct ata_host_set *host_set = dev_instance;
1266 unsigned int hc, handled = 0, n_hcs;
Brett Russ31961942005-09-30 01:36:00 -04001267 void __iomem *mmio = host_set->mmio_base;
Brett Russ20f733e2005-09-01 18:26:17 -04001268 u32 irq_stat;
1269
Brett Russ20f733e2005-09-01 18:26:17 -04001270 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001271
1272 /* check the cases where we either have nothing pending or have read
1273 * a bogus register value which can indicate HW removal or PCI fault
1274 */
1275 if (!irq_stat || (0xffffffffU == irq_stat)) {
1276 return IRQ_NONE;
1277 }
1278
Brett Russ31961942005-09-30 01:36:00 -04001279 n_hcs = mv_get_hc_count(host_set->ports[0]->flags);
Brett Russ20f733e2005-09-01 18:26:17 -04001280 spin_lock(&host_set->lock);
1281
1282 for (hc = 0; hc < n_hcs; hc++) {
1283 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
1284 if (relevant) {
1285 mv_host_intr(host_set, relevant, hc);
Brett Russ31961942005-09-30 01:36:00 -04001286 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001287 }
1288 }
1289 if (PCI_ERR & irq_stat) {
Brett Russ31961942005-09-30 01:36:00 -04001290 printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n",
1291 readl(mmio + PCI_IRQ_CAUSE_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04001292
Brett Russafb0edd2005-10-05 17:08:42 -04001293 DPRINTK("All regs @ PCI error\n");
Brett Russ31961942005-09-30 01:36:00 -04001294 mv_dump_all_regs(mmio, -1, to_pci_dev(host_set->dev));
1295
1296 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1297 handled++;
1298 }
Brett Russ20f733e2005-09-01 18:26:17 -04001299 spin_unlock(&host_set->lock);
1300
1301 return IRQ_RETVAL(handled);
1302}
1303
Jeff Garzikc9d39132005-11-13 17:47:51 -05001304static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port)
1305{
1306 void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port);
1307 unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL;
1308
1309 return hc_mmio + ofs;
1310}
1311
1312static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
1313{
1314 unsigned int ofs;
1315
1316 switch (sc_reg_in) {
1317 case SCR_STATUS:
1318 case SCR_ERROR:
1319 case SCR_CONTROL:
1320 ofs = sc_reg_in * sizeof(u32);
1321 break;
1322 default:
1323 ofs = 0xffffffffU;
1324 break;
1325 }
1326 return ofs;
1327}
1328
1329static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
1330{
1331 void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no);
1332 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1333
1334 if (ofs != 0xffffffffU)
1335 return readl(mmio + ofs);
1336 else
1337 return (u32) ofs;
1338}
1339
1340static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
1341{
1342 void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no);
1343 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1344
1345 if (ofs != 0xffffffffU)
1346 writelfl(val, mmio + ofs);
1347}
1348
Jeff Garzik522479f2005-11-12 22:14:02 -05001349static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
1350{
1351 u8 rev_id;
1352 int early_5080;
1353
1354 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1355
1356 early_5080 = (pdev->device == 0x5080) && (rev_id == 0);
1357
1358 if (!early_5080) {
1359 u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1360 tmp |= (1 << 0);
1361 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
1362 }
1363
1364 mv_reset_pci_bus(pdev, mmio);
1365}
1366
1367static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1368{
1369 writel(0x0fcfffff, mmio + MV_FLASH_CTL);
1370}
1371
Jeff Garzik47c2b672005-11-12 21:13:17 -05001372static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001373 void __iomem *mmio)
1374{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001375 void __iomem *phy_mmio = mv5_phy_base(mmio, idx);
1376 u32 tmp;
1377
1378 tmp = readl(phy_mmio + MV5_PHY_MODE);
1379
1380 hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */
1381 hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001382}
1383
Jeff Garzik47c2b672005-11-12 21:13:17 -05001384static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001385{
Jeff Garzik522479f2005-11-12 22:14:02 -05001386 u32 tmp;
1387
1388 writel(0, mmio + MV_GPIO_PORT_CTL);
1389
1390 /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */
1391
1392 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1393 tmp |= ~(1 << 0);
1394 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001395}
1396
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001397static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
1398 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001399{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001400 void __iomem *phy_mmio = mv5_phy_base(mmio, port);
1401 const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5);
1402 u32 tmp;
1403 int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0);
1404
1405 if (fix_apm_sq) {
1406 tmp = readl(phy_mmio + MV5_LT_MODE);
1407 tmp |= (1 << 19);
1408 writel(tmp, phy_mmio + MV5_LT_MODE);
1409
1410 tmp = readl(phy_mmio + MV5_PHY_CTL);
1411 tmp &= ~0x3;
1412 tmp |= 0x1;
1413 writel(tmp, phy_mmio + MV5_PHY_CTL);
1414 }
1415
1416 tmp = readl(phy_mmio + MV5_PHY_MODE);
1417 tmp &= ~mask;
1418 tmp |= hpriv->signal[port].pre;
1419 tmp |= hpriv->signal[port].amps;
1420 writel(tmp, phy_mmio + MV5_PHY_MODE);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001421}
1422
Jeff Garzikc9d39132005-11-13 17:47:51 -05001423
1424#undef ZERO
1425#define ZERO(reg) writel(0, port_mmio + (reg))
1426static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio,
1427 unsigned int port)
Jeff Garzik47c2b672005-11-12 21:13:17 -05001428{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001429 void __iomem *port_mmio = mv_port_base(mmio, port);
1430
1431 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
1432
1433 mv_channel_reset(hpriv, mmio, port);
1434
1435 ZERO(0x028); /* command */
1436 writel(0x11f, port_mmio + EDMA_CFG_OFS);
1437 ZERO(0x004); /* timer */
1438 ZERO(0x008); /* irq err cause */
1439 ZERO(0x00c); /* irq err mask */
1440 ZERO(0x010); /* rq bah */
1441 ZERO(0x014); /* rq inp */
1442 ZERO(0x018); /* rq outp */
1443 ZERO(0x01c); /* respq bah */
1444 ZERO(0x024); /* respq outp */
1445 ZERO(0x020); /* respq inp */
1446 ZERO(0x02c); /* test control */
1447 writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
1448}
1449#undef ZERO
1450
1451#define ZERO(reg) writel(0, hc_mmio + (reg))
1452static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1453 unsigned int hc)
1454{
1455 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1456 u32 tmp;
1457
1458 ZERO(0x00c);
1459 ZERO(0x010);
1460 ZERO(0x014);
1461 ZERO(0x018);
1462
1463 tmp = readl(hc_mmio + 0x20);
1464 tmp &= 0x1c1c1c1c;
1465 tmp |= 0x03030303;
1466 writel(tmp, hc_mmio + 0x20);
1467}
1468#undef ZERO
1469
1470static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1471 unsigned int n_hc)
1472{
1473 unsigned int hc, port;
1474
1475 for (hc = 0; hc < n_hc; hc++) {
1476 for (port = 0; port < MV_PORTS_PER_HC; port++)
1477 mv5_reset_hc_port(hpriv, mmio,
1478 (hc * MV_PORTS_PER_HC) + port);
1479
1480 mv5_reset_one_hc(hpriv, mmio, hc);
1481 }
1482
1483 return 0;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001484}
1485
Jeff Garzik101ffae2005-11-12 22:17:49 -05001486#undef ZERO
1487#define ZERO(reg) writel(0, mmio + (reg))
1488static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
1489{
1490 u32 tmp;
1491
1492 tmp = readl(mmio + MV_PCI_MODE);
1493 tmp &= 0xff00ffff;
1494 writel(tmp, mmio + MV_PCI_MODE);
1495
1496 ZERO(MV_PCI_DISC_TIMER);
1497 ZERO(MV_PCI_MSI_TRIGGER);
1498 writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT);
1499 ZERO(HC_MAIN_IRQ_MASK_OFS);
1500 ZERO(MV_PCI_SERR_MASK);
1501 ZERO(PCI_IRQ_CAUSE_OFS);
1502 ZERO(PCI_IRQ_MASK_OFS);
1503 ZERO(MV_PCI_ERR_LOW_ADDRESS);
1504 ZERO(MV_PCI_ERR_HIGH_ADDRESS);
1505 ZERO(MV_PCI_ERR_ATTRIBUTE);
1506 ZERO(MV_PCI_ERR_COMMAND);
1507}
1508#undef ZERO
1509
1510static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1511{
1512 u32 tmp;
1513
1514 mv5_reset_flash(hpriv, mmio);
1515
1516 tmp = readl(mmio + MV_GPIO_PORT_CTL);
1517 tmp &= 0x3;
1518 tmp |= (1 << 5) | (1 << 6);
1519 writel(tmp, mmio + MV_GPIO_PORT_CTL);
1520}
1521
1522/**
1523 * mv6_reset_hc - Perform the 6xxx global soft reset
1524 * @mmio: base address of the HBA
1525 *
1526 * This routine only applies to 6xxx parts.
1527 *
1528 * LOCKING:
1529 * Inherited from caller.
1530 */
Jeff Garzikc9d39132005-11-13 17:47:51 -05001531static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1532 unsigned int n_hc)
Jeff Garzik101ffae2005-11-12 22:17:49 -05001533{
1534 void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS;
1535 int i, rc = 0;
1536 u32 t;
1537
1538 /* Following procedure defined in PCI "main command and status
1539 * register" table.
1540 */
1541 t = readl(reg);
1542 writel(t | STOP_PCI_MASTER, reg);
1543
1544 for (i = 0; i < 1000; i++) {
1545 udelay(1);
1546 t = readl(reg);
1547 if (PCI_MASTER_EMPTY & t) {
1548 break;
1549 }
1550 }
1551 if (!(PCI_MASTER_EMPTY & t)) {
1552 printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
1553 rc = 1;
1554 goto done;
1555 }
1556
1557 /* set reset */
1558 i = 5;
1559 do {
1560 writel(t | GLOB_SFT_RST, reg);
1561 t = readl(reg);
1562 udelay(1);
1563 } while (!(GLOB_SFT_RST & t) && (i-- > 0));
1564
1565 if (!(GLOB_SFT_RST & t)) {
1566 printk(KERN_ERR DRV_NAME ": can't set global reset\n");
1567 rc = 1;
1568 goto done;
1569 }
1570
1571 /* clear reset and *reenable the PCI master* (not mentioned in spec) */
1572 i = 5;
1573 do {
1574 writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
1575 t = readl(reg);
1576 udelay(1);
1577 } while ((GLOB_SFT_RST & t) && (i-- > 0));
1578
1579 if (GLOB_SFT_RST & t) {
1580 printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
1581 rc = 1;
1582 }
1583done:
1584 return rc;
1585}
1586
Jeff Garzik47c2b672005-11-12 21:13:17 -05001587static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001588 void __iomem *mmio)
1589{
1590 void __iomem *port_mmio;
1591 u32 tmp;
1592
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001593 tmp = readl(mmio + MV_RESET_CFG);
1594 if ((tmp & (1 << 0)) == 0) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001595 hpriv->signal[idx].amps = 0x7 << 8;
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001596 hpriv->signal[idx].pre = 0x1 << 5;
1597 return;
1598 }
1599
1600 port_mmio = mv_port_base(mmio, idx);
1601 tmp = readl(port_mmio + PHY_MODE2);
1602
1603 hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
1604 hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
1605}
1606
Jeff Garzik47c2b672005-11-12 21:13:17 -05001607static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001608{
Jeff Garzik47c2b672005-11-12 21:13:17 -05001609 writel(0x00000060, mmio + MV_GPIO_PORT_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001610}
1611
Jeff Garzikc9d39132005-11-13 17:47:51 -05001612static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001613 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001614{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001615 void __iomem *port_mmio = mv_port_base(mmio, port);
1616
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001617 u32 hp_flags = hpriv->hp_flags;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001618 int fix_phy_mode2 =
1619 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001620 int fix_phy_mode4 =
Jeff Garzik47c2b672005-11-12 21:13:17 -05001621 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
1622 u32 m2, tmp;
1623
1624 if (fix_phy_mode2) {
1625 m2 = readl(port_mmio + PHY_MODE2);
1626 m2 &= ~(1 << 16);
1627 m2 |= (1 << 31);
1628 writel(m2, port_mmio + PHY_MODE2);
1629
1630 udelay(200);
1631
1632 m2 = readl(port_mmio + PHY_MODE2);
1633 m2 &= ~((1 << 16) | (1 << 31));
1634 writel(m2, port_mmio + PHY_MODE2);
1635
1636 udelay(200);
1637 }
1638
1639 /* who knows what this magic does */
1640 tmp = readl(port_mmio + PHY_MODE3);
1641 tmp &= ~0x7F800000;
1642 tmp |= 0x2A800000;
1643 writel(tmp, port_mmio + PHY_MODE3);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001644
1645 if (fix_phy_mode4) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001646 u32 m4;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001647
1648 m4 = readl(port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001649
1650 if (hp_flags & MV_HP_ERRATA_60X1B2)
1651 tmp = readl(port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001652
1653 m4 = (m4 & ~(1 << 1)) | (1 << 0);
1654
1655 writel(m4, port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001656
1657 if (hp_flags & MV_HP_ERRATA_60X1B2)
1658 writel(tmp, port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001659 }
1660
1661 /* Revert values of pre-emphasis and signal amps to the saved ones */
1662 m2 = readl(port_mmio + PHY_MODE2);
1663
1664 m2 &= ~MV_M2_PREAMP_MASK;
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001665 m2 |= hpriv->signal[port].amps;
1666 m2 |= hpriv->signal[port].pre;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001667 m2 &= ~(1 << 16);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001668
1669 writel(m2, port_mmio + PHY_MODE2);
1670}
1671
Jeff Garzikc9d39132005-11-13 17:47:51 -05001672static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1673 unsigned int port_no)
Brett Russ20f733e2005-09-01 18:26:17 -04001674{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001675 void __iomem *port_mmio = mv_port_base(mmio, port_no);
Brett Russ20f733e2005-09-01 18:26:17 -04001676
Brett Russ31961942005-09-30 01:36:00 -04001677 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001678
1679 if (IS_60XX(hpriv)) {
1680 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
1681 ifctl |= (1 << 12) | (1 << 7);
1682 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
1683 }
1684
Brett Russ20f733e2005-09-01 18:26:17 -04001685 udelay(25); /* allow reset propagation */
1686
1687 /* Spec never mentions clearing the bit. Marvell's driver does
1688 * clear the bit, however.
1689 */
Brett Russ31961942005-09-30 01:36:00 -04001690 writelfl(0, port_mmio + EDMA_CMD_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001691
Jeff Garzikc9d39132005-11-13 17:47:51 -05001692 hpriv->ops->phy_errata(hpriv, mmio, port_no);
1693
1694 if (IS_50XX(hpriv))
1695 mdelay(1);
1696}
1697
1698static void mv_stop_and_reset(struct ata_port *ap)
1699{
1700 struct mv_host_priv *hpriv = ap->host_set->private_data;
1701 void __iomem *mmio = ap->host_set->mmio_base;
1702
1703 mv_stop_dma(ap);
1704
1705 mv_channel_reset(hpriv, mmio, ap->port_no);
1706
Jeff Garzik22374672005-11-17 10:59:48 -05001707 __mv_phy_reset(ap, 0);
1708}
1709
1710static inline void __msleep(unsigned int msec, int can_sleep)
1711{
1712 if (can_sleep)
1713 msleep(msec);
1714 else
1715 mdelay(msec);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001716}
1717
1718/**
Jeff Garzik22374672005-11-17 10:59:48 -05001719 * __mv_phy_reset - Perform eDMA reset followed by COMRESET
Jeff Garzikc9d39132005-11-13 17:47:51 -05001720 * @ap: ATA channel to manipulate
1721 *
1722 * Part of this is taken from __sata_phy_reset and modified to
1723 * not sleep since this routine gets called from interrupt level.
1724 *
1725 * LOCKING:
1726 * Inherited from caller. This is coded to safe to call at
1727 * interrupt level, i.e. it does not sleep.
1728 */
Jeff Garzik22374672005-11-17 10:59:48 -05001729static void __mv_phy_reset(struct ata_port *ap, int can_sleep)
Jeff Garzikc9d39132005-11-13 17:47:51 -05001730{
1731 struct mv_port_priv *pp = ap->private_data;
Jeff Garzik22374672005-11-17 10:59:48 -05001732 struct mv_host_priv *hpriv = ap->host_set->private_data;
Jeff Garzikc9d39132005-11-13 17:47:51 -05001733 void __iomem *port_mmio = mv_ap_base(ap);
1734 struct ata_taskfile tf;
1735 struct ata_device *dev = &ap->device[0];
1736 unsigned long timeout;
Jeff Garzik22374672005-11-17 10:59:48 -05001737 int retry = 5;
1738 u32 sstatus;
Jeff Garzikc9d39132005-11-13 17:47:51 -05001739
1740 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001741
Jeff Garzik095fec82005-11-12 09:50:49 -05001742 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001743 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1744 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
Brett Russ20f733e2005-09-01 18:26:17 -04001745
Jeff Garzik22374672005-11-17 10:59:48 -05001746 /* Issue COMRESET via SControl */
1747comreset_retry:
Brett Russ31961942005-09-30 01:36:00 -04001748 scr_write_flush(ap, SCR_CONTROL, 0x301);
Jeff Garzik22374672005-11-17 10:59:48 -05001749 __msleep(1, can_sleep);
1750
Brett Russ31961942005-09-30 01:36:00 -04001751 scr_write_flush(ap, SCR_CONTROL, 0x300);
Jeff Garzik22374672005-11-17 10:59:48 -05001752 __msleep(20, can_sleep);
1753
1754 timeout = jiffies + msecs_to_jiffies(200);
Brett Russ31961942005-09-30 01:36:00 -04001755 do {
Jeff Garzik22374672005-11-17 10:59:48 -05001756 sstatus = scr_read(ap, SCR_STATUS) & 0x3;
1757 if ((sstatus == 3) || (sstatus == 0))
Brett Russ31961942005-09-30 01:36:00 -04001758 break;
Jeff Garzik22374672005-11-17 10:59:48 -05001759
1760 __msleep(1, can_sleep);
Brett Russ31961942005-09-30 01:36:00 -04001761 } while (time_before(jiffies, timeout));
Brett Russ20f733e2005-09-01 18:26:17 -04001762
Jeff Garzik22374672005-11-17 10:59:48 -05001763 /* work around errata */
1764 if (IS_60XX(hpriv) &&
1765 (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) &&
1766 (retry-- > 0))
1767 goto comreset_retry;
Jeff Garzik095fec82005-11-12 09:50:49 -05001768
1769 DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001770 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1771 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
1772
1773 if (sata_dev_present(ap)) {
1774 ata_port_probe(ap);
1775 } else {
1776 printk(KERN_INFO "ata%u: no device found (phy stat %08x)\n",
1777 ap->id, scr_read(ap, SCR_STATUS));
1778 ata_port_disable(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001779 return;
1780 }
Brett Russ31961942005-09-30 01:36:00 -04001781 ap->cbl = ATA_CBL_SATA;
Brett Russ20f733e2005-09-01 18:26:17 -04001782
Jeff Garzik22374672005-11-17 10:59:48 -05001783 /* even after SStatus reflects that device is ready,
1784 * it seems to take a while for link to be fully
1785 * established (and thus Status no longer 0x80/0x7F),
1786 * so we poll a bit for that, here.
1787 */
1788 retry = 20;
1789 while (1) {
1790 u8 drv_stat = ata_check_status(ap);
1791 if ((drv_stat != 0x80) && (drv_stat != 0x7f))
1792 break;
1793 __msleep(500, can_sleep);
1794 if (retry-- <= 0)
1795 break;
1796 }
1797
Brett Russ20f733e2005-09-01 18:26:17 -04001798 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr);
1799 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr);
1800 tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr);
1801 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr);
1802
1803 dev->class = ata_dev_classify(&tf);
1804 if (!ata_dev_present(dev)) {
1805 VPRINTK("Port disabled post-sig: No device present.\n");
1806 ata_port_disable(ap);
1807 }
Jeff Garzik095fec82005-11-12 09:50:49 -05001808
1809 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1810
1811 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1812
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001813 VPRINTK("EXIT\n");
Brett Russ20f733e2005-09-01 18:26:17 -04001814}
1815
Jeff Garzik22374672005-11-17 10:59:48 -05001816static void mv_phy_reset(struct ata_port *ap)
1817{
1818 __mv_phy_reset(ap, 1);
1819}
1820
Brett Russ05b308e2005-10-05 17:08:53 -04001821/**
1822 * mv_eng_timeout - Routine called by libata when SCSI times out I/O
1823 * @ap: ATA channel to manipulate
1824 *
1825 * Intent is to clear all pending error conditions, reset the
1826 * chip/bus, fail the command, and move on.
1827 *
1828 * LOCKING:
1829 * This routine holds the host_set lock while failing the command.
1830 */
Brett Russ31961942005-09-30 01:36:00 -04001831static void mv_eng_timeout(struct ata_port *ap)
Brett Russ20f733e2005-09-01 18:26:17 -04001832{
Brett Russ31961942005-09-30 01:36:00 -04001833 struct ata_queued_cmd *qc;
1834 unsigned long flags;
1835
1836 printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id);
1837 DPRINTK("All regs @ start of eng_timeout\n");
Jeff Garzik8b260242005-11-12 12:32:50 -05001838 mv_dump_all_regs(ap->host_set->mmio_base, ap->port_no,
Brett Russ31961942005-09-30 01:36:00 -04001839 to_pci_dev(ap->host_set->dev));
1840
1841 qc = ata_qc_from_tag(ap, ap->active_tag);
1842 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
Jeff Garzik8b260242005-11-12 12:32:50 -05001843 ap->host_set->mmio_base, ap, qc, qc->scsicmd,
Brett Russ31961942005-09-30 01:36:00 -04001844 &qc->scsicmd->cmnd);
1845
1846 mv_err_intr(ap);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001847 mv_stop_and_reset(ap);
Brett Russ31961942005-09-30 01:36:00 -04001848
1849 if (!qc) {
1850 printk(KERN_ERR "ata%u: BUG: timeout without command\n",
1851 ap->id);
1852 } else {
1853 /* hack alert! We cannot use the supplied completion
1854 * function from inside the ->eh_strategy_handler() thread.
1855 * libata is the only user of ->eh_strategy_handler() in
1856 * any kernel, so the default scsi_done() assumes it is
1857 * not being called from the SCSI EH.
1858 */
1859 spin_lock_irqsave(&ap->host_set->lock, flags);
1860 qc->scsidone = scsi_finish_command;
Jeff Garzika7dac442005-10-30 04:44:42 -05001861 ata_qc_complete(qc, AC_ERR_OTHER);
Brett Russ31961942005-09-30 01:36:00 -04001862 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1863 }
1864}
1865
Brett Russ05b308e2005-10-05 17:08:53 -04001866/**
1867 * mv_port_init - Perform some early initialization on a single port.
1868 * @port: libata data structure storing shadow register addresses
1869 * @port_mmio: base address of the port
1870 *
1871 * Initialize shadow register mmio addresses, clear outstanding
1872 * interrupts on the port, and unmask interrupts for the future
1873 * start of the port.
1874 *
1875 * LOCKING:
1876 * Inherited from caller.
1877 */
Brett Russ31961942005-09-30 01:36:00 -04001878static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
1879{
1880 unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS;
1881 unsigned serr_ofs;
1882
Jeff Garzik8b260242005-11-12 12:32:50 -05001883 /* PIO related setup
Brett Russ31961942005-09-30 01:36:00 -04001884 */
1885 port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
Jeff Garzik8b260242005-11-12 12:32:50 -05001886 port->error_addr =
Brett Russ31961942005-09-30 01:36:00 -04001887 port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
1888 port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
1889 port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
1890 port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
1891 port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
1892 port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
Jeff Garzik8b260242005-11-12 12:32:50 -05001893 port->status_addr =
Brett Russ31961942005-09-30 01:36:00 -04001894 port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
1895 /* special case: control/altstatus doesn't have ATA_REG_ address */
1896 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
1897
1898 /* unused: */
Brett Russ20f733e2005-09-01 18:26:17 -04001899 port->cmd_addr = port->bmdma_addr = port->scr_addr = 0;
1900
Brett Russ31961942005-09-30 01:36:00 -04001901 /* Clear any currently outstanding port interrupt conditions */
1902 serr_ofs = mv_scr_offset(SCR_ERROR);
1903 writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
1904 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1905
Brett Russ20f733e2005-09-01 18:26:17 -04001906 /* unmask all EDMA error interrupts */
Brett Russ31961942005-09-30 01:36:00 -04001907 writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001908
Jeff Garzik8b260242005-11-12 12:32:50 -05001909 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
Brett Russ31961942005-09-30 01:36:00 -04001910 readl(port_mmio + EDMA_CFG_OFS),
1911 readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
1912 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04001913}
1914
Jeff Garzik47c2b672005-11-12 21:13:17 -05001915static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
Jeff Garzik522479f2005-11-12 22:14:02 -05001916 unsigned int board_idx)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001917{
1918 u8 rev_id;
1919 u32 hp_flags = hpriv->hp_flags;
1920
1921 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1922
1923 switch(board_idx) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001924 case chip_5080:
1925 hpriv->ops = &mv5xxx_ops;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001926 hp_flags |= MV_HP_50XX;
1927
Jeff Garzik47c2b672005-11-12 21:13:17 -05001928 switch (rev_id) {
1929 case 0x1:
1930 hp_flags |= MV_HP_ERRATA_50XXB0;
1931 break;
1932 case 0x3:
1933 hp_flags |= MV_HP_ERRATA_50XXB2;
1934 break;
1935 default:
1936 dev_printk(KERN_WARNING, &pdev->dev,
1937 "Applying 50XXB2 workarounds to unknown rev\n");
1938 hp_flags |= MV_HP_ERRATA_50XXB2;
1939 break;
1940 }
1941 break;
1942
1943 case chip_504x:
1944 case chip_508x:
1945 hpriv->ops = &mv5xxx_ops;
1946 hp_flags |= MV_HP_50XX;
1947
1948 switch (rev_id) {
1949 case 0x0:
1950 hp_flags |= MV_HP_ERRATA_50XXB0;
1951 break;
1952 case 0x3:
1953 hp_flags |= MV_HP_ERRATA_50XXB2;
1954 break;
1955 default:
1956 dev_printk(KERN_WARNING, &pdev->dev,
1957 "Applying B2 workarounds to unknown rev\n");
1958 hp_flags |= MV_HP_ERRATA_50XXB2;
1959 break;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001960 }
1961 break;
1962
1963 case chip_604x:
1964 case chip_608x:
Jeff Garzik47c2b672005-11-12 21:13:17 -05001965 hpriv->ops = &mv6xxx_ops;
1966
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001967 switch (rev_id) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001968 case 0x7:
1969 hp_flags |= MV_HP_ERRATA_60X1B2;
1970 break;
1971 case 0x9:
1972 hp_flags |= MV_HP_ERRATA_60X1C0;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001973 break;
1974 default:
1975 dev_printk(KERN_WARNING, &pdev->dev,
Jeff Garzik47c2b672005-11-12 21:13:17 -05001976 "Applying B2 workarounds to unknown rev\n");
1977 hp_flags |= MV_HP_ERRATA_60X1B2;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001978 break;
1979 }
1980 break;
1981
1982 default:
1983 printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx);
1984 return 1;
1985 }
1986
1987 hpriv->hp_flags = hp_flags;
1988
1989 return 0;
1990}
1991
Brett Russ05b308e2005-10-05 17:08:53 -04001992/**
Jeff Garzik47c2b672005-11-12 21:13:17 -05001993 * mv_init_host - Perform some early initialization of the host.
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001994 * @pdev: host PCI device
Brett Russ05b308e2005-10-05 17:08:53 -04001995 * @probe_ent: early data struct representing the host
1996 *
1997 * If possible, do an early global reset of the host. Then do
1998 * our port init and clear/unmask all/relevant host interrupts.
1999 *
2000 * LOCKING:
2001 * Inherited from caller.
2002 */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002003static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002004 unsigned int board_idx)
Brett Russ20f733e2005-09-01 18:26:17 -04002005{
2006 int rc = 0, n_hc, port, hc;
2007 void __iomem *mmio = probe_ent->mmio_base;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002008 struct mv_host_priv *hpriv = probe_ent->private_data;
2009
Jeff Garzik47c2b672005-11-12 21:13:17 -05002010 /* global interrupt mask */
2011 writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
2012
2013 rc = mv_chip_id(pdev, hpriv, board_idx);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002014 if (rc)
2015 goto done;
2016
2017 n_hc = mv_get_hc_count(probe_ent->host_flags);
2018 probe_ent->n_ports = MV_PORTS_PER_HC * n_hc;
2019
Jeff Garzik47c2b672005-11-12 21:13:17 -05002020 for (port = 0; port < probe_ent->n_ports; port++)
2021 hpriv->ops->read_preamp(hpriv, port, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002022
Jeff Garzikc9d39132005-11-13 17:47:51 -05002023 rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002024 if (rc)
Brett Russ20f733e2005-09-01 18:26:17 -04002025 goto done;
Brett Russ20f733e2005-09-01 18:26:17 -04002026
Jeff Garzik522479f2005-11-12 22:14:02 -05002027 hpriv->ops->reset_flash(hpriv, mmio);
2028 hpriv->ops->reset_bus(pdev, mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002029 hpriv->ops->enable_leds(hpriv, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002030
2031 for (port = 0; port < probe_ent->n_ports; port++) {
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002032 if (IS_60XX(hpriv)) {
Jeff Garzikc9d39132005-11-13 17:47:51 -05002033 void __iomem *port_mmio = mv_port_base(mmio, port);
2034
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002035 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
2036 ifctl |= (1 << 12);
2037 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
2038 }
2039
Jeff Garzikc9d39132005-11-13 17:47:51 -05002040 hpriv->ops->phy_errata(hpriv, mmio, port);
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002041 }
2042
2043 for (port = 0; port < probe_ent->n_ports; port++) {
2044 void __iomem *port_mmio = mv_port_base(mmio, port);
Brett Russ31961942005-09-30 01:36:00 -04002045 mv_port_init(&probe_ent->port[port], port_mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002046 }
2047
2048 for (hc = 0; hc < n_hc; hc++) {
Brett Russ31961942005-09-30 01:36:00 -04002049 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
2050
2051 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
2052 "(before clear)=0x%08x\n", hc,
2053 readl(hc_mmio + HC_CFG_OFS),
2054 readl(hc_mmio + HC_IRQ_CAUSE_OFS));
2055
2056 /* Clear any currently outstanding hc interrupt conditions */
2057 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002058 }
2059
Brett Russ31961942005-09-30 01:36:00 -04002060 /* Clear any currently outstanding host interrupt conditions */
2061 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
2062
2063 /* and unmask interrupt generation for host regs */
2064 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
2065 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002066
2067 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
Jeff Garzik8b260242005-11-12 12:32:50 -05002068 "PCI int cause/mask=0x%08x/0x%08x\n",
Brett Russ20f733e2005-09-01 18:26:17 -04002069 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
2070 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
2071 readl(mmio + PCI_IRQ_CAUSE_OFS),
2072 readl(mmio + PCI_IRQ_MASK_OFS));
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002073
Brett Russ31961942005-09-30 01:36:00 -04002074done:
Brett Russ20f733e2005-09-01 18:26:17 -04002075 return rc;
2076}
2077
Brett Russ05b308e2005-10-05 17:08:53 -04002078/**
2079 * mv_print_info - Dump key info to kernel log for perusal.
2080 * @probe_ent: early data struct representing the host
2081 *
2082 * FIXME: complete this.
2083 *
2084 * LOCKING:
2085 * Inherited from caller.
2086 */
Brett Russ31961942005-09-30 01:36:00 -04002087static void mv_print_info(struct ata_probe_ent *probe_ent)
2088{
2089 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
2090 struct mv_host_priv *hpriv = probe_ent->private_data;
2091 u8 rev_id, scc;
2092 const char *scc_s;
2093
2094 /* Use this to determine the HW stepping of the chip so we know
2095 * what errata to workaround
2096 */
2097 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
2098
2099 pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
2100 if (scc == 0)
2101 scc_s = "SCSI";
2102 else if (scc == 0x01)
2103 scc_s = "RAID";
2104 else
2105 scc_s = "unknown";
2106
Jeff Garzika9524a72005-10-30 14:39:11 -05002107 dev_printk(KERN_INFO, &pdev->dev,
2108 "%u slots %u ports %s mode IRQ via %s\n",
Jeff Garzik8b260242005-11-12 12:32:50 -05002109 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports,
Brett Russ31961942005-09-30 01:36:00 -04002110 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
2111}
2112
Brett Russ05b308e2005-10-05 17:08:53 -04002113/**
2114 * mv_init_one - handle a positive probe of a Marvell host
2115 * @pdev: PCI device found
2116 * @ent: PCI device ID entry for the matched host
2117 *
2118 * LOCKING:
2119 * Inherited from caller.
2120 */
Brett Russ20f733e2005-09-01 18:26:17 -04002121static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2122{
2123 static int printed_version = 0;
2124 struct ata_probe_ent *probe_ent = NULL;
2125 struct mv_host_priv *hpriv;
2126 unsigned int board_idx = (unsigned int)ent->driver_data;
2127 void __iomem *mmio_base;
Brett Russ31961942005-09-30 01:36:00 -04002128 int pci_dev_busy = 0, rc;
Brett Russ20f733e2005-09-01 18:26:17 -04002129
Jeff Garzika9524a72005-10-30 14:39:11 -05002130 if (!printed_version++)
2131 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
Brett Russ20f733e2005-09-01 18:26:17 -04002132
Brett Russ20f733e2005-09-01 18:26:17 -04002133 rc = pci_enable_device(pdev);
2134 if (rc) {
2135 return rc;
2136 }
2137
2138 rc = pci_request_regions(pdev, DRV_NAME);
2139 if (rc) {
2140 pci_dev_busy = 1;
2141 goto err_out;
2142 }
2143
Brett Russ20f733e2005-09-01 18:26:17 -04002144 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL);
2145 if (probe_ent == NULL) {
2146 rc = -ENOMEM;
2147 goto err_out_regions;
2148 }
2149
2150 memset(probe_ent, 0, sizeof(*probe_ent));
2151 probe_ent->dev = pci_dev_to_dev(pdev);
2152 INIT_LIST_HEAD(&probe_ent->node);
2153
Brett Russ31961942005-09-30 01:36:00 -04002154 mmio_base = pci_iomap(pdev, MV_PRIMARY_BAR, 0);
Brett Russ20f733e2005-09-01 18:26:17 -04002155 if (mmio_base == NULL) {
2156 rc = -ENOMEM;
2157 goto err_out_free_ent;
2158 }
2159
2160 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
2161 if (!hpriv) {
2162 rc = -ENOMEM;
2163 goto err_out_iounmap;
2164 }
2165 memset(hpriv, 0, sizeof(*hpriv));
2166
2167 probe_ent->sht = mv_port_info[board_idx].sht;
2168 probe_ent->host_flags = mv_port_info[board_idx].host_flags;
2169 probe_ent->pio_mask = mv_port_info[board_idx].pio_mask;
2170 probe_ent->udma_mask = mv_port_info[board_idx].udma_mask;
2171 probe_ent->port_ops = mv_port_info[board_idx].port_ops;
2172
2173 probe_ent->irq = pdev->irq;
2174 probe_ent->irq_flags = SA_SHIRQ;
2175 probe_ent->mmio_base = mmio_base;
2176 probe_ent->private_data = hpriv;
2177
2178 /* initialize adapter */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002179 rc = mv_init_host(pdev, probe_ent, board_idx);
Brett Russ20f733e2005-09-01 18:26:17 -04002180 if (rc) {
2181 goto err_out_hpriv;
2182 }
Brett Russ20f733e2005-09-01 18:26:17 -04002183
Brett Russ31961942005-09-30 01:36:00 -04002184 /* Enable interrupts */
2185 if (pci_enable_msi(pdev) == 0) {
2186 hpriv->hp_flags |= MV_HP_FLAG_MSI;
2187 } else {
2188 pci_intx(pdev, 1);
Brett Russ20f733e2005-09-01 18:26:17 -04002189 }
2190
Brett Russ31961942005-09-30 01:36:00 -04002191 mv_dump_pci_cfg(pdev, 0x68);
2192 mv_print_info(probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002193
Brett Russ31961942005-09-30 01:36:00 -04002194 if (ata_device_add(probe_ent) == 0) {
2195 rc = -ENODEV; /* No devices discovered */
2196 goto err_out_dev_add;
2197 }
2198
2199 kfree(probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002200 return 0;
2201
Brett Russ31961942005-09-30 01:36:00 -04002202err_out_dev_add:
2203 if (MV_HP_FLAG_MSI & hpriv->hp_flags) {
2204 pci_disable_msi(pdev);
2205 } else {
2206 pci_intx(pdev, 0);
2207 }
2208err_out_hpriv:
Brett Russ20f733e2005-09-01 18:26:17 -04002209 kfree(hpriv);
Brett Russ31961942005-09-30 01:36:00 -04002210err_out_iounmap:
2211 pci_iounmap(pdev, mmio_base);
2212err_out_free_ent:
Brett Russ20f733e2005-09-01 18:26:17 -04002213 kfree(probe_ent);
Brett Russ31961942005-09-30 01:36:00 -04002214err_out_regions:
Brett Russ20f733e2005-09-01 18:26:17 -04002215 pci_release_regions(pdev);
Brett Russ31961942005-09-30 01:36:00 -04002216err_out:
Brett Russ20f733e2005-09-01 18:26:17 -04002217 if (!pci_dev_busy) {
2218 pci_disable_device(pdev);
2219 }
2220
2221 return rc;
2222}
2223
2224static int __init mv_init(void)
2225{
2226 return pci_module_init(&mv_pci_driver);
2227}
2228
2229static void __exit mv_exit(void)
2230{
2231 pci_unregister_driver(&mv_pci_driver);
2232}
2233
2234MODULE_AUTHOR("Brett Russ");
2235MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
2236MODULE_LICENSE("GPL");
2237MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
2238MODULE_VERSION(DRV_VERSION);
2239
2240module_init(mv_init);
2241module_exit(mv_exit);