4 * Synopsys DesignWare Cores (DWC) SATA host driver
6 * Author: Mark Miesfeld <mmiesfeld@amcc.com>
8 * Ported from 2.6.19.2 to 2.6.25/26 by Stefan Roese <sr@denx.de>
9 * Copyright 2008 DENX Software Engineering
11 * Based on versions provided by AMCC and Synopsys which are:
12 * Copyright 2006 Applied Micro Circuits Corporation
13 * COPYRIGHT (C) 2005 SYNOPSYS, INC. ALL RIGHTS RESERVED
15 * This program is free software; you can redistribute
16 * it and/or modify it under the terms of the GNU
17 * General Public License as published by the
18 * Free Software Foundation; either version 2 of the License,
19 * or (at your option) any later version.
23 * SATA support based on the chip canyonlands.
26 * The local version of this driver for the canyonlands board
27 * does not use interrupts but polls the chip instead.
41 ATA_READID_POSTRESET = (1 << 0),
46 ATA_DNXFER_FORCE_PIO = 3,
47 ATA_DNXFER_FORCE_PIO0 = 4,
49 ATA_DNXFER_QUIET = (1 << 31),
52 enum hsm_task_states {
60 #define ATA_SHORT_PAUSE ((HZ >> 6) + 1)
62 struct ata_queued_cmd {
64 struct ata_device *dev;
66 struct ata_taskfile tf;
67 u8 cdb[ATAPI_CDB_LEN];
73 unsigned int sect_size;
76 unsigned int extrabytes;
77 unsigned int curbytes;
79 unsigned int err_mask;
80 struct ata_taskfile result_tf;
89 typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
91 #define ATA_TAG_POISON 0xfafbfcfdU
94 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
95 LIBATA_DUMB_MAX_PRD = ATA_MAX_PRD / 4,
99 ATA_TAG_INTERNAL = ATA_MAX_QUEUE - 1,
101 ATA_DEF_BUSY_WAIT = 10000,
103 ATAPI_MAX_DRAIN = 16 << 10,
105 ATA_SHT_EMULATED = 1,
106 ATA_SHT_CMD_PER_LUN = 1,
107 ATA_SHT_THIS_ID = -1,
108 ATA_SHT_USE_CLUSTERING = 1,
110 ATA_DFLAG_LBA = (1 << 0),
111 ATA_DFLAG_LBA48 = (1 << 1),
112 ATA_DFLAG_CDB_INTR = (1 << 2),
113 ATA_DFLAG_NCQ = (1 << 3),
114 ATA_DFLAG_FLUSH_EXT = (1 << 4),
115 ATA_DFLAG_ACPI_PENDING = (1 << 5),
116 ATA_DFLAG_ACPI_FAILED = (1 << 6),
117 ATA_DFLAG_AN = (1 << 7),
118 ATA_DFLAG_HIPM = (1 << 8),
119 ATA_DFLAG_DIPM = (1 << 9),
120 ATA_DFLAG_DMADIR = (1 << 10),
121 ATA_DFLAG_CFG_MASK = (1 << 12) - 1,
123 ATA_DFLAG_PIO = (1 << 12),
124 ATA_DFLAG_NCQ_OFF = (1 << 13),
125 ATA_DFLAG_SPUNDOWN = (1 << 14),
126 ATA_DFLAG_SLEEPING = (1 << 15),
127 ATA_DFLAG_DUBIOUS_XFER = (1 << 16),
128 ATA_DFLAG_INIT_MASK = (1 << 24) - 1,
130 ATA_DFLAG_DETACH = (1 << 24),
131 ATA_DFLAG_DETACHED = (1 << 25),
133 ATA_LFLAG_HRST_TO_RESUME = (1 << 0),
134 ATA_LFLAG_SKIP_D2H_BSY = (1 << 1),
135 ATA_LFLAG_NO_SRST = (1 << 2),
136 ATA_LFLAG_ASSUME_ATA = (1 << 3),
137 ATA_LFLAG_ASSUME_SEMB = (1 << 4),
138 ATA_LFLAG_ASSUME_CLASS = ATA_LFLAG_ASSUME_ATA | ATA_LFLAG_ASSUME_SEMB,
139 ATA_LFLAG_NO_RETRY = (1 << 5),
140 ATA_LFLAG_DISABLED = (1 << 6),
142 ATA_FLAG_SLAVE_POSS = (1 << 0),
143 ATA_FLAG_SATA = (1 << 1),
144 ATA_FLAG_NO_LEGACY = (1 << 2),
145 ATA_FLAG_MMIO = (1 << 3),
146 ATA_FLAG_SRST = (1 << 4),
147 ATA_FLAG_SATA_RESET = (1 << 5),
148 ATA_FLAG_NO_ATAPI = (1 << 6),
149 ATA_FLAG_PIO_DMA = (1 << 7),
150 ATA_FLAG_PIO_LBA48 = (1 << 8),
151 ATA_FLAG_PIO_POLLING = (1 << 9),
152 ATA_FLAG_NCQ = (1 << 10),
153 ATA_FLAG_DEBUGMSG = (1 << 13),
154 ATA_FLAG_IGN_SIMPLEX = (1 << 15),
155 ATA_FLAG_NO_IORDY = (1 << 16),
156 ATA_FLAG_ACPI_SATA = (1 << 17),
157 ATA_FLAG_AN = (1 << 18),
158 ATA_FLAG_PMP = (1 << 19),
159 ATA_FLAG_IPM = (1 << 20),
161 ATA_FLAG_DISABLED = (1 << 23),
163 ATA_PFLAG_EH_PENDING = (1 << 0),
164 ATA_PFLAG_EH_IN_PROGRESS = (1 << 1),
165 ATA_PFLAG_FROZEN = (1 << 2),
166 ATA_PFLAG_RECOVERED = (1 << 3),
167 ATA_PFLAG_LOADING = (1 << 4),
168 ATA_PFLAG_UNLOADING = (1 << 5),
169 ATA_PFLAG_SCSI_HOTPLUG = (1 << 6),
170 ATA_PFLAG_INITIALIZING = (1 << 7),
171 ATA_PFLAG_RESETTING = (1 << 8),
172 ATA_PFLAG_SUSPENDED = (1 << 17),
173 ATA_PFLAG_PM_PENDING = (1 << 18),
175 ATA_QCFLAG_ACTIVE = (1 << 0),
176 ATA_QCFLAG_DMAMAP = (1 << 1),
177 ATA_QCFLAG_IO = (1 << 3),
178 ATA_QCFLAG_RESULT_TF = (1 << 4),
179 ATA_QCFLAG_CLEAR_EXCL = (1 << 5),
180 ATA_QCFLAG_QUIET = (1 << 6),
182 ATA_QCFLAG_FAILED = (1 << 16),
183 ATA_QCFLAG_SENSE_VALID = (1 << 17),
184 ATA_QCFLAG_EH_SCHEDULED = (1 << 18),
186 ATA_HOST_SIMPLEX = (1 << 0),
187 ATA_HOST_STARTED = (1 << 1),
189 ATA_TMOUT_BOOT = 30 * 100,
190 ATA_TMOUT_BOOT_QUICK = 7 * 100,
191 ATA_TMOUT_INTERNAL = 30 * 100,
192 ATA_TMOUT_INTERNAL_QUICK = 5 * 100,
194 /* FIXME: GoVault needs 2s but we can't afford that without
195 * parallel probing. 800ms is enough for iVDR disk
196 * HHD424020F7SV00. Increase to 2secs when parallel probing
199 ATA_TMOUT_FF_WAIT = 4 * 100 / 5,
216 /* encoding various smaller bitmaps into a single
217 * unsigned long bitmap
219 ATA_NR_PIO_MODES = 7,
220 ATA_NR_MWDMA_MODES = 5,
221 ATA_NR_UDMA_MODES = 8,
224 ATA_SHIFT_MWDMA = ATA_SHIFT_PIO + ATA_NR_PIO_MODES,
225 ATA_SHIFT_UDMA = ATA_SHIFT_MWDMA + ATA_NR_MWDMA_MODES,
234 ATA_EH_DESC_LEN = 80,
236 ATA_EH_REVALIDATE = (1 << 0),
237 ATA_EH_SOFTRESET = (1 << 1),
238 ATA_EH_HARDRESET = (1 << 2),
239 ATA_EH_ENABLE_LINK = (1 << 3),
240 ATA_EH_LPM = (1 << 4),
242 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
243 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE,
245 ATA_EHI_HOTPLUGGED = (1 << 0),
246 ATA_EHI_RESUME_LINK = (1 << 1),
247 ATA_EHI_NO_AUTOPSY = (1 << 2),
248 ATA_EHI_QUIET = (1 << 3),
250 ATA_EHI_DID_SOFTRESET = (1 << 16),
251 ATA_EHI_DID_HARDRESET = (1 << 17),
252 ATA_EHI_PRINTINFO = (1 << 18),
253 ATA_EHI_SETMODE = (1 << 19),
254 ATA_EHI_POST_SETMODE = (1 << 20),
256 ATA_EHI_DID_RESET = ATA_EHI_DID_SOFTRESET | ATA_EHI_DID_HARDRESET,
257 ATA_EHI_RESET_MODIFIER_MASK = ATA_EHI_RESUME_LINK,
259 ATA_EH_MAX_TRIES = 5,
261 ATA_PROBE_MAX_TRIES = 3,
262 ATA_EH_DEV_TRIES = 3,
263 ATA_EH_PMP_TRIES = 5,
264 ATA_EH_PMP_LINK_TRIES = 3,
266 SATA_PMP_SCR_TIMEOUT = 250,
268 /* Horkage types. May be set by libata or controller on drives
269 (some horkage may be drive/controller pair dependant */
271 ATA_HORKAGE_DIAGNOSTIC = (1 << 0),
272 ATA_HORKAGE_NODMA = (1 << 1),
273 ATA_HORKAGE_NONCQ = (1 << 2),
274 ATA_HORKAGE_MAX_SEC_128 = (1 << 3),
275 ATA_HORKAGE_BROKEN_HPA = (1 << 4),
276 ATA_HORKAGE_SKIP_PM = (1 << 5),
277 ATA_HORKAGE_HPA_SIZE = (1 << 6),
278 ATA_HORKAGE_IPM = (1 << 7),
279 ATA_HORKAGE_IVB = (1 << 8),
280 ATA_HORKAGE_STUCK_ERR = (1 << 9),
282 ATA_DMA_MASK_ATA = (1 << 0),
283 ATA_DMA_MASK_ATAPI = (1 << 1),
284 ATA_DMA_MASK_CFA = (1 << 2),
293 enum ata_completion_errors {
294 AC_ERR_DEV = (1 << 0),
295 AC_ERR_HSM = (1 << 1),
296 AC_ERR_TIMEOUT = (1 << 2),
297 AC_ERR_MEDIA = (1 << 3),
298 AC_ERR_ATA_BUS = (1 << 4),
299 AC_ERR_HOST_BUS = (1 << 5),
300 AC_ERR_SYSTEM = (1 << 6),
301 AC_ERR_INVALID = (1 << 7),
302 AC_ERR_OTHER = (1 << 8),
303 AC_ERR_NODEV_HINT = (1 << 9),
304 AC_ERR_NCQ = (1 << 10),
308 ATA_MASK_PIO = ((1LU << ATA_NR_PIO_MODES) - 1) << ATA_SHIFT_PIO,
309 ATA_MASK_MWDMA = ((1LU << ATA_NR_MWDMA_MODES) - 1) << ATA_SHIFT_MWDMA,
310 ATA_MASK_UDMA = ((1LU << ATA_NR_UDMA_MODES) - 1) << ATA_SHIFT_UDMA,
313 struct ata_port_info {
315 struct scsi_host_template *sht;
318 unsigned long link_flags;
319 unsigned long pio_mask;
320 unsigned long mwdma_mask;
321 unsigned long udma_mask;
323 const struct ata_port_operations *port_ops;
329 void __iomem *cmd_addr;
330 void __iomem *data_addr;
331 void __iomem *error_addr;
332 void __iomem *feature_addr;
333 void __iomem *nsect_addr;
334 void __iomem *lbal_addr;
335 void __iomem *lbam_addr;
336 void __iomem *lbah_addr;
337 void __iomem *device_addr;
338 void __iomem *status_addr;
339 void __iomem *command_addr;
340 void __iomem *altstatus_addr;
341 void __iomem *ctl_addr;
343 void __iomem *bmdma_addr;
345 void __iomem *scr_addr;
350 void __iomem * const *iomap;
352 const struct ata_port_operations *ops;
354 struct ata_port *simplex_claimed;
356 unsigned int n_ports;
357 struct ata_port *ports[0];
361 struct ata_port_stats {
362 unsigned long unhandled_irq;
363 unsigned long idle_irq;
364 unsigned long rw_reqbuf;
369 struct ata_link *link;
372 unsigned int horkage;
374 struct scsi_device *sdev;
375 #ifdef CONFIG_ATA_ACPI
376 acpi_handle acpi_handle;
377 union acpi_object *gtf_cache;
384 u16 id[ATA_ID_WORDS];
385 u32 gscr[SATA_PMP_GSCR_DWORDS];
391 unsigned int xfer_shift;
393 unsigned int multi_count;
394 unsigned int max_sectors;
395 unsigned int cdb_len;
397 unsigned long pio_mask;
398 unsigned long mwdma_mask;
400 unsigned long udma_mask;
409 enum dma_data_direction {
410 DMA_BIDIRECTIONAL = 0,
419 unsigned int active_tag;
422 unsigned int hw_sata_spd_limit;
424 unsigned int sata_spd_limit;
425 unsigned int sata_spd;
426 struct ata_device device[2];
433 unsigned int print_id;
434 unsigned int port_no;
436 struct ata_ioports ioaddr;
440 unsigned int pio_mask;
441 unsigned int mwdma_mask;
442 unsigned int udma_mask;
445 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE];
446 unsigned long qc_allocated;
447 unsigned int qc_active;
450 struct ata_link link;
453 struct ata_link *pmp_link;
455 struct ata_link *excl_link;
458 struct ata_port_stats stats;
462 struct ata_host *host;
463 void *port_task_data;
465 unsigned int hsm_task_state;
467 unsigned char *pdata;