Blame view
drivers/ata/sata_sil.c
22 KB
1da177e4c
|
1 2 3 4 5 6 7 |
/* * sata_sil.c - Silicon Image SATA * * Maintained by: Jeff Garzik <jgarzik@pobox.com> * Please ALWAYS copy linux-ide@vger.kernel.org * on emails. * |
af36d7f0d
|
8 |
* Copyright 2003-2005 Red Hat, Inc. |
1da177e4c
|
9 10 |
* Copyright 2003 Benjamin Herrenschmidt * |
af36d7f0d
|
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * * libata documentation is available via 'make {ps|pdf}docs', * as Documentation/DocBook/libata.* |
1da177e4c
|
29 |
* |
953d1137f
|
30 31 32 33 34 |
* Documentation for SiI 3112: * http://gkernel.sourceforge.net/specs/sii/3112A_SiI-DS-0095-B2.pdf.bz2 * * Other errata and documentation available under NDA. * |
1da177e4c
|
35 36 37 38 39 40 41 42 43 |
*/ #include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> #include <linux/init.h> #include <linux/blkdev.h> #include <linux/delay.h> #include <linux/interrupt.h> |
a9524a76f
|
44 |
#include <linux/device.h> |
1da177e4c
|
45 46 |
#include <scsi/scsi_host.h> #include <linux/libata.h> |
1737ef759
|
47 |
#include <linux/dmi.h> |
1da177e4c
|
48 49 |
#define DRV_NAME "sata_sil" |
c7e324f1b
|
50 51 52 |
#define DRV_VERSION "2.4" #define SIL_DMA_BOUNDARY 0x7fffffffUL |
1da177e4c
|
53 54 |
enum { |
0d5ff5667
|
55 |
SIL_MMIO_BAR = 5, |
e653a1e61
|
56 57 58 |
/* * host flags */ |
201ce8594
|
59 |
SIL_FLAG_NO_SATA_IRQ = (1 << 28), |
e4e10e3e7
|
60 |
SIL_FLAG_RERR_ON_DMA_ACT = (1 << 29), |
e4deec630
|
61 |
SIL_FLAG_MOD15WRITE = (1 << 30), |
20888d836
|
62 |
|
9cbe056f6
|
63 |
SIL_DFL_PORT_FLAGS = ATA_FLAG_SATA, |
e4deec630
|
64 |
|
e653a1e61
|
65 66 67 |
/* * Controller IDs */ |
1da177e4c
|
68 |
sil_3112 = 0, |
201ce8594
|
69 70 71 |
sil_3112_no_sata_irq = 1, sil_3512 = 2, sil_3114 = 3, |
1da177e4c
|
72 |
|
e653a1e61
|
73 74 75 |
/* * Register offsets */ |
1da177e4c
|
76 |
SIL_SYSCFG = 0x48, |
e653a1e61
|
77 78 79 80 81 |
/* * Register bits */ /* SYSCFG */ |
1da177e4c
|
82 83 84 85 86 87 88 |
SIL_MASK_IDE0_INT = (1 << 22), SIL_MASK_IDE1_INT = (1 << 23), SIL_MASK_IDE2_INT = (1 << 24), SIL_MASK_IDE3_INT = (1 << 25), SIL_MASK_2PORT = SIL_MASK_IDE0_INT | SIL_MASK_IDE1_INT, SIL_MASK_4PORT = SIL_MASK_2PORT | SIL_MASK_IDE2_INT | SIL_MASK_IDE3_INT, |
e653a1e61
|
89 |
/* BMDMA/BMDMA2 */ |
1da177e4c
|
90 |
SIL_INTR_STEERING = (1 << 1), |
e653a1e61
|
91 |
|
20888d836
|
92 93 94 95 96 97 98 99 100 101 102 103 104 |
SIL_DMA_ENABLE = (1 << 0), /* DMA run switch */ SIL_DMA_RDWR = (1 << 3), /* DMA Rd-Wr */ SIL_DMA_SATA_IRQ = (1 << 4), /* OR of all SATA IRQs */ SIL_DMA_ACTIVE = (1 << 16), /* DMA running */ SIL_DMA_ERROR = (1 << 17), /* PCI bus error */ SIL_DMA_COMPLETE = (1 << 18), /* cmd complete / IRQ pending */ SIL_DMA_N_SATA_IRQ = (1 << 6), /* SATA_IRQ for the next channel */ SIL_DMA_N_ACTIVE = (1 << 24), /* ACTIVE for the next channel */ SIL_DMA_N_ERROR = (1 << 25), /* ERROR for the next channel */ SIL_DMA_N_COMPLETE = (1 << 26), /* COMPLETE for the next channel */ /* SIEN */ SIL_SIEN_N = (1 << 16), /* triggered by SError.N */ |
e653a1e61
|
105 106 107 |
/* * Others */ |
1da177e4c
|
108 109 110 |
SIL_QUIRK_MOD15WRITE = (1 << 0), SIL_QUIRK_UDMA5MAX = (1 << 1), }; |
5796d1c4c
|
111 |
static int sil_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
281d426c7
|
112 |
#ifdef CONFIG_PM |
afb5a7cb8
|
113 |
static int sil_pci_device_resume(struct pci_dev *pdev); |
281d426c7
|
114 |
#endif |
cd0d3bbcd
|
115 |
static void sil_dev_config(struct ata_device *dev); |
82ef04fb4
|
116 117 |
static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val); static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val); |
0260731f0
|
118 |
static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed); |
c7e324f1b
|
119 120 121 122 |
static void sil_qc_prep(struct ata_queued_cmd *qc); static void sil_bmdma_setup(struct ata_queued_cmd *qc); static void sil_bmdma_start(struct ata_queued_cmd *qc); static void sil_bmdma_stop(struct ata_queued_cmd *qc); |
f6aae27ed
|
123 124 |
static void sil_freeze(struct ata_port *ap); static void sil_thaw(struct ata_port *ap); |
1da177e4c
|
125 |
|
374b18735
|
126 |
|
3b7d697df
|
127 |
static const struct pci_device_id sil_pci_tbl[] = { |
54bb3a94b
|
128 129 130 131 132 133 134 |
{ PCI_VDEVICE(CMD, 0x3112), sil_3112 }, { PCI_VDEVICE(CMD, 0x0240), sil_3112 }, { PCI_VDEVICE(CMD, 0x3512), sil_3512 }, { PCI_VDEVICE(CMD, 0x3114), sil_3114 }, { PCI_VDEVICE(ATI, 0x436e), sil_3112 }, { PCI_VDEVICE(ATI, 0x4379), sil_3112_no_sata_irq }, { PCI_VDEVICE(ATI, 0x437a), sil_3112_no_sata_irq }, |
1da177e4c
|
135 136 137 138 139 140 |
{ } /* terminate list */ }; /* TODO firmware versions should be added - eric */ static const struct sil_drivelist { |
5796d1c4c
|
141 |
const char *product; |
1da177e4c
|
142 143 144 145 146 147 |
unsigned int quirk; } sil_blacklist [] = { { "ST320012AS", SIL_QUIRK_MOD15WRITE }, { "ST330013AS", SIL_QUIRK_MOD15WRITE }, { "ST340017AS", SIL_QUIRK_MOD15WRITE }, { "ST360015AS", SIL_QUIRK_MOD15WRITE }, |
1da177e4c
|
148 149 |
{ "ST380023AS", SIL_QUIRK_MOD15WRITE }, { "ST3120023AS", SIL_QUIRK_MOD15WRITE }, |
1da177e4c
|
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
{ "ST340014ASL", SIL_QUIRK_MOD15WRITE }, { "ST360014ASL", SIL_QUIRK_MOD15WRITE }, { "ST380011ASL", SIL_QUIRK_MOD15WRITE }, { "ST3120022ASL", SIL_QUIRK_MOD15WRITE }, { "ST3160021ASL", SIL_QUIRK_MOD15WRITE }, { "Maxtor 4D060H3", SIL_QUIRK_UDMA5MAX }, { } }; static struct pci_driver sil_pci_driver = { .name = DRV_NAME, .id_table = sil_pci_tbl, .probe = sil_init_one, .remove = ata_pci_remove_one, |
281d426c7
|
164 |
#ifdef CONFIG_PM |
afb5a7cb8
|
165 166 |
.suspend = ata_pci_device_suspend, .resume = sil_pci_device_resume, |
281d426c7
|
167 |
#endif |
1da177e4c
|
168 |
}; |
193515d51
|
169 |
static struct scsi_host_template sil_sht = { |
c7e324f1b
|
170 171 172 173 174 175 |
ATA_BASE_SHT(DRV_NAME), /** These controllers support Large Block Transfer which allows transfer chunks up to 2GB and which cross 64KB boundaries, therefore the DMA limits are more relaxed than standard ATA SFF. */ .dma_boundary = SIL_DMA_BOUNDARY, .sg_tablesize = ATA_MAX_PRD |
1da177e4c
|
176 |
}; |
029cfd6b7
|
177 |
static struct ata_port_operations sil_ops = { |
31f80112c
|
178 |
.inherits = &ata_bmdma32_port_ops, |
1da177e4c
|
179 |
.dev_config = sil_dev_config, |
9d2c7c75f
|
180 |
.set_mode = sil_set_mode, |
c7e324f1b
|
181 182 183 184 |
.bmdma_setup = sil_bmdma_setup, .bmdma_start = sil_bmdma_start, .bmdma_stop = sil_bmdma_stop, .qc_prep = sil_qc_prep, |
f6aae27ed
|
185 186 |
.freeze = sil_freeze, .thaw = sil_thaw, |
1da177e4c
|
187 188 |
.scr_read = sil_scr_read, .scr_write = sil_scr_write, |
1da177e4c
|
189 |
}; |
98ac62def
|
190 |
static const struct ata_port_info sil_port_info[] = { |
1da177e4c
|
191 192 |
/* sil_3112 */ { |
cca3974e4
|
193 |
.flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE, |
14bdef982
|
194 195 |
.pio_mask = ATA_PIO4, .mwdma_mask = ATA_MWDMA2, |
bf6263a85
|
196 |
.udma_mask = ATA_UDMA5, |
e4deec630
|
197 |
.port_ops = &sil_ops, |
0ee304d58
|
198 |
}, |
201ce8594
|
199 200 |
/* sil_3112_no_sata_irq */ { |
cca3974e4
|
201 |
.flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE | |
201ce8594
|
202 |
SIL_FLAG_NO_SATA_IRQ, |
14bdef982
|
203 204 |
.pio_mask = ATA_PIO4, .mwdma_mask = ATA_MWDMA2, |
bf6263a85
|
205 |
.udma_mask = ATA_UDMA5, |
201ce8594
|
206 207 |
.port_ops = &sil_ops, }, |
0ee304d58
|
208 |
/* sil_3512 */ |
1da177e4c
|
209 |
{ |
cca3974e4
|
210 |
.flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, |
14bdef982
|
211 212 |
.pio_mask = ATA_PIO4, .mwdma_mask = ATA_MWDMA2, |
bf6263a85
|
213 |
.udma_mask = ATA_UDMA5, |
0ee304d58
|
214 215 216 |
.port_ops = &sil_ops, }, /* sil_3114 */ |
1da177e4c
|
217 |
{ |
cca3974e4
|
218 |
.flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, |
14bdef982
|
219 220 |
.pio_mask = ATA_PIO4, .mwdma_mask = ATA_MWDMA2, |
bf6263a85
|
221 |
.udma_mask = ATA_UDMA5, |
1da177e4c
|
222 223 224 225 226 227 228 229 230 231 |
.port_ops = &sil_ops, }, }; /* per-port register offsets */ /* TODO: we can probably calculate rather than use a table */ static const struct { unsigned long tf; /* ATA taskfile register block */ unsigned long ctl; /* ATA control/altstatus register block */ unsigned long bmdma; /* DMA register block */ |
20888d836
|
232 |
unsigned long bmdma2; /* DMA register block #2 */ |
48d4ef2a1
|
233 |
unsigned long fifo_cfg; /* FIFO Valid Byte Count and Control */ |
1da177e4c
|
234 235 236 |
unsigned long scr; /* SATA control register block */ unsigned long sien; /* SATA Interrupt Enable register */ unsigned long xfer_mode;/* data transfer mode register */ |
e4e10e3e7
|
237 |
unsigned long sfis_cfg; /* SATA FIS reception config register */ |
1da177e4c
|
238 239 |
} sil_port[] = { /* port 0 ... */ |
5bcd7a00a
|
240 241 242 |
/* tf ctl bmdma bmdma2 fifo scr sien mode sfis */ { 0x80, 0x8A, 0x0, 0x10, 0x40, 0x100, 0x148, 0xb4, 0x14c }, { 0xC0, 0xCA, 0x8, 0x18, 0x44, 0x180, 0x1c8, 0xf4, 0x1cc }, |
20888d836
|
243 244 |
{ 0x280, 0x28A, 0x200, 0x210, 0x240, 0x300, 0x348, 0x2b4, 0x34c }, { 0x2C0, 0x2CA, 0x208, 0x218, 0x244, 0x380, 0x3c8, 0x2f4, 0x3cc }, |
1da177e4c
|
245 246 247 248 249 250 251 252 |
/* ... port 3 */ }; MODULE_AUTHOR("Jeff Garzik"); MODULE_DESCRIPTION("low-level driver for Silicon Image SATA controller"); MODULE_LICENSE("GPL"); MODULE_DEVICE_TABLE(pci, sil_pci_tbl); MODULE_VERSION(DRV_VERSION); |
5796d1c4c
|
253 |
static int slow_down; |
51e9f2ff8
|
254 255 |
module_param(slow_down, int, 0444); MODULE_PARM_DESC(slow_down, "Sledgehammer used to work around random problems, by limiting commands to 15 sectors (0=off, 1=on)"); |
374b18735
|
256 |
|
c7e324f1b
|
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
static void sil_bmdma_stop(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR]; void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2; /* clear start/stop bit - can safely always write 0 */ iowrite8(0, bmdma2); /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ ata_sff_dma_pause(ap); } static void sil_bmdma_setup(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; void __iomem *bmdma = ap->ioaddr.bmdma_addr; /* load PRD table addr. */ |
f60d70113
|
276 |
iowrite32(ap->bmdma_prd_dma, bmdma + ATA_DMA_TABLE_OFS); |
c7e324f1b
|
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
/* issue r/w command */ ap->ops->sff_exec_command(ap, &qc->tf); } static void sil_bmdma_start(struct ata_queued_cmd *qc) { unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); struct ata_port *ap = qc->ap; void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR]; void __iomem *bmdma2 = mmio_base + sil_port[ap->port_no].bmdma2; u8 dmactl = ATA_DMA_START; /* set transfer direction, start host DMA transaction Note: For Large Block Transfer to work, the DMA must be started using the bmdma2 register. */ if (!rw) dmactl |= ATA_DMA_WR; iowrite8(dmactl, bmdma2); } /* The way God intended PCI IDE scatter/gather lists to look and behave... */ static void sil_fill_sg(struct ata_queued_cmd *qc) { struct scatterlist *sg; struct ata_port *ap = qc->ap; |
f60d70113
|
303 |
struct ata_bmdma_prd *prd, *last_prd = NULL; |
c7e324f1b
|
304 |
unsigned int si; |
f60d70113
|
305 |
prd = &ap->bmdma_prd[0]; |
c7e324f1b
|
306 307 308 309 310 311 312 313 314 |
for_each_sg(qc->sg, sg, qc->n_elem, si) { /* Note h/w doesn't support 64-bit, so we unconditionally * truncate dma_addr_t to u32. */ u32 addr = (u32) sg_dma_address(sg); u32 sg_len = sg_dma_len(sg); prd->addr = cpu_to_le32(addr); prd->flags_len = cpu_to_le32(sg_len); |
41137aa61
|
315 316 |
VPRINTK("PRD[%u] = (0x%X, 0x%X) ", si, addr, sg_len); |
c7e324f1b
|
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
last_prd = prd; prd++; } if (likely(last_prd)) last_prd->flags_len |= cpu_to_le32(ATA_PRD_EOT); } static void sil_qc_prep(struct ata_queued_cmd *qc) { if (!(qc->flags & ATA_QCFLAG_DMAMAP)) return; sil_fill_sg(qc); } |
1da177e4c
|
333 334 335 336 337 338 |
static unsigned char sil_get_device_cache_line(struct pci_dev *pdev) { u8 cache_line = 0; pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line); return cache_line; } |
9d2c7c75f
|
339 340 |
/** * sil_set_mode - wrap set_mode functions |
0260731f0
|
341 |
* @link: link to set up |
9d2c7c75f
|
342 343 344 345 346 |
* @r_failed: returned device when we fail * * Wrap the libata method for device setup as after the setup we need * to inspect the results and do some configuration work */ |
0260731f0
|
347 |
static int sil_set_mode(struct ata_link *link, struct ata_device **r_failed) |
1da177e4c
|
348 |
{ |
0260731f0
|
349 350 |
struct ata_port *ap = link->ap; void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR]; |
0d5ff5667
|
351 |
void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode; |
0260731f0
|
352 |
struct ata_device *dev; |
f58229f80
|
353 |
u32 tmp, dev_mode[2] = { }; |
9d2c7c75f
|
354 |
int rc; |
a617c09f6
|
355 |
|
0260731f0
|
356 |
rc = ata_do_set_mode(link, r_failed); |
9d2c7c75f
|
357 358 |
if (rc) return rc; |
1da177e4c
|
359 |
|
1eca4365b
|
360 |
ata_for_each_dev(dev, link, ALL) { |
e1211e3fa
|
361 |
if (!ata_dev_enabled(dev)) |
f58229f80
|
362 |
dev_mode[dev->devno] = 0; /* PIO0/1/2 */ |
1da177e4c
|
363 |
else if (dev->flags & ATA_DFLAG_PIO) |
f58229f80
|
364 |
dev_mode[dev->devno] = 1; /* PIO3/4 */ |
1da177e4c
|
365 |
else |
f58229f80
|
366 |
dev_mode[dev->devno] = 3; /* UDMA */ |
1da177e4c
|
367 368 369 370 371 372 373 374 375 |
/* value 2 indicates MDMA */ } tmp = readl(addr); tmp &= ~((1<<5) | (1<<4) | (1<<1) | (1<<0)); tmp |= dev_mode[0]; tmp |= (dev_mode[1] << 4); writel(tmp, addr); readl(addr); /* flush */ |
9d2c7c75f
|
376 |
return 0; |
1da177e4c
|
377 |
} |
5796d1c4c
|
378 379 |
static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_reg) |
1da177e4c
|
380 |
{ |
0d5ff5667
|
381 |
void __iomem *offset = ap->ioaddr.scr_addr; |
1da177e4c
|
382 383 384 385 386 387 388 389 390 391 392 393 |
switch (sc_reg) { case SCR_STATUS: return offset + 4; case SCR_ERROR: return offset + 8; case SCR_CONTROL: return offset; default: /* do nothing */ break; } |
8d9db2d2f
|
394 |
return NULL; |
1da177e4c
|
395 |
} |
82ef04fb4
|
396 |
static int sil_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val) |
1da177e4c
|
397 |
{ |
82ef04fb4
|
398 |
void __iomem *mmio = sil_scr_addr(link->ap, sc_reg); |
da3dbb17a
|
399 400 401 402 403 404 |
if (mmio) { *val = readl(mmio); return 0; } return -EINVAL; |
1da177e4c
|
405 |
} |
82ef04fb4
|
406 |
static int sil_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val) |
1da177e4c
|
407 |
{ |
82ef04fb4
|
408 |
void __iomem *mmio = sil_scr_addr(link->ap, sc_reg); |
da3dbb17a
|
409 410 |
if (mmio) { |
1da177e4c
|
411 |
writel(val, mmio); |
da3dbb17a
|
412 413 414 |
return 0; } return -EINVAL; |
1da177e4c
|
415 |
} |
cbe88fbc7
|
416 417 |
static void sil_host_intr(struct ata_port *ap, u32 bmdma2) { |
9af5c9c97
|
418 419 |
struct ata_eh_info *ehi = &ap->link.eh_info; struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag); |
cbe88fbc7
|
420 |
u8 status; |
e573890b0
|
421 |
if (unlikely(bmdma2 & SIL_DMA_SATA_IRQ)) { |
ebd1699ec
|
422 |
u32 serror = 0xffffffff; |
d4c85325a
|
423 424 425 426 427 |
/* SIEN doesn't mask SATA IRQs on some 3112s. Those * controllers continue to assert IRQ as long as * SError bits are pending. Clear SError immediately. */ |
82ef04fb4
|
428 429 |
sil_scr_read(&ap->link, SCR_ERROR, &serror); sil_scr_write(&ap->link, SCR_ERROR, serror); |
d4c85325a
|
430 |
|
8cf32ac65
|
431 432 |
/* Sometimes spurious interrupts occur, double check * it's PHYRDY CHG. |
d4c85325a
|
433 |
*/ |
8cf32ac65
|
434 |
if (serror & SERR_PHYRDY_CHG) { |
f7fe7ad4b
|
435 |
ap->link.eh_info.serror |= serror; |
8cf32ac65
|
436 |
goto freeze; |
d4c85325a
|
437 |
} |
8cf32ac65
|
438 439 |
if (!(bmdma2 & SIL_DMA_COMPLETE)) return; |
e573890b0
|
440 |
} |
8cf32ac65
|
441 |
if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) { |
e2f8fb721
|
442 |
/* this sometimes happens, just clear IRQ */ |
5682ed33a
|
443 |
ap->ops->sff_check_status(ap); |
e2f8fb721
|
444 445 |
return; } |
cbe88fbc7
|
446 447 448 449 450 451 452 453 |
/* Check whether we are expecting interrupt in this state */ switch (ap->hsm_task_state) { case HSM_ST_FIRST: /* Some pre-ATAPI-4 devices assert INTRQ * at this state when ready to receive CDB. */ /* Check the ATA_DFLAG_CDB_INTR flag is enough here. |
405e66b38
|
454 455 |
* The flag was turned on only for atapi devices. No * need to check ata_is_atapi(qc->tf.protocol) again. |
cbe88fbc7
|
456 457 458 459 460 |
*/ if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) goto err_hsm; break; case HSM_ST_LAST: |
405e66b38
|
461 |
if (ata_is_dma(qc->tf.protocol)) { |
cbe88fbc7
|
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
/* clear DMA-Start bit */ ap->ops->bmdma_stop(qc); if (bmdma2 & SIL_DMA_ERROR) { qc->err_mask |= AC_ERR_HOST_BUS; ap->hsm_task_state = HSM_ST_ERR; } } break; case HSM_ST: break; default: goto err_hsm; } /* check main status, clearing INTRQ */ |
5682ed33a
|
478 |
status = ap->ops->sff_check_status(ap); |
cbe88fbc7
|
479 480 481 482 |
if (unlikely(status & ATA_BUSY)) goto err_hsm; /* ack bmdma irq events */ |
37f65b8bc
|
483 |
ata_bmdma_irq_clear(ap); |
cbe88fbc7
|
484 485 |
/* kick HSM in the ass */ |
9363c3825
|
486 |
ata_sff_hsm_move(ap, qc, status, 0); |
cbe88fbc7
|
487 |
|
405e66b38
|
488 |
if (unlikely(qc->err_mask) && ata_is_dma(qc->tf.protocol)) |
ea54763f8
|
489 |
ata_ehi_push_desc(ehi, "BMDMA2 stat 0x%x", bmdma2); |
cbe88fbc7
|
490 491 492 493 494 495 496 |
return; err_hsm: qc->err_mask |= AC_ERR_HSM; freeze: ata_port_freeze(ap); } |
7d12e780e
|
497 |
static irqreturn_t sil_interrupt(int irq, void *dev_instance) |
cbe88fbc7
|
498 |
{ |
cca3974e4
|
499 |
struct ata_host *host = dev_instance; |
0d5ff5667
|
500 |
void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR]; |
cbe88fbc7
|
501 502 |
int handled = 0; int i; |
cca3974e4
|
503 |
spin_lock(&host->lock); |
cbe88fbc7
|
504 |
|
cca3974e4
|
505 506 |
for (i = 0; i < host->n_ports; i++) { struct ata_port *ap = host->ports[i]; |
cbe88fbc7
|
507 |
u32 bmdma2 = readl(mmio_base + sil_port[ap->port_no].bmdma2); |
201ce8594
|
508 509 510 |
/* turn off SATA_IRQ if not supported */ if (ap->flags & SIL_FLAG_NO_SATA_IRQ) bmdma2 &= ~SIL_DMA_SATA_IRQ; |
23fa96180
|
511 512 |
if (bmdma2 == 0xffffffff || !(bmdma2 & (SIL_DMA_COMPLETE | SIL_DMA_SATA_IRQ))) |
cbe88fbc7
|
513 514 515 516 517 |
continue; sil_host_intr(ap, bmdma2); handled = 1; } |
cca3974e4
|
518 |
spin_unlock(&host->lock); |
cbe88fbc7
|
519 520 521 |
return IRQ_RETVAL(handled); } |
f6aae27ed
|
522 523 |
static void sil_freeze(struct ata_port *ap) { |
0d5ff5667
|
524 |
void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR]; |
f6aae27ed
|
525 |
u32 tmp; |
e573890b0
|
526 527 |
/* global IRQ mask doesn't block SATA IRQ, turn off explicitly */ writel(0, mmio_base + sil_port[ap->port_no].sien); |
f6aae27ed
|
528 529 530 531 532 |
/* plug IRQ */ tmp = readl(mmio_base + SIL_SYSCFG); tmp |= SIL_MASK_IDE0_INT << ap->port_no; writel(tmp, mmio_base + SIL_SYSCFG); readl(mmio_base + SIL_SYSCFG); /* flush */ |
2fc37adba
|
533 534 535 536 537 538 539 540 541 542 543 544 545 |
/* Ensure DMA_ENABLE is off. * * This is because the controller will not give us access to the * taskfile registers while a DMA is in progress */ iowrite8(ioread8(ap->ioaddr.bmdma_addr) & ~SIL_DMA_ENABLE, ap->ioaddr.bmdma_addr); /* According to ata_bmdma_stop, an HDMA transition requires * on PIO cycle. But we can't read a taskfile register. */ ioread8(ap->ioaddr.bmdma_addr); |
f6aae27ed
|
546 547 548 549 |
} static void sil_thaw(struct ata_port *ap) { |
0d5ff5667
|
550 |
void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR]; |
f6aae27ed
|
551 552 553 |
u32 tmp; /* clear IRQ */ |
5682ed33a
|
554 |
ap->ops->sff_check_status(ap); |
37f65b8bc
|
555 |
ata_bmdma_irq_clear(ap); |
f6aae27ed
|
556 |
|
201ce8594
|
557 558 559 |
/* turn on SATA IRQ if supported */ if (!(ap->flags & SIL_FLAG_NO_SATA_IRQ)) writel(SIL_SIEN_N, mmio_base + sil_port[ap->port_no].sien); |
e573890b0
|
560 |
|
f6aae27ed
|
561 562 563 564 565 |
/* turn on IRQ */ tmp = readl(mmio_base + SIL_SYSCFG); tmp &= ~(SIL_MASK_IDE0_INT << ap->port_no); writel(tmp, mmio_base + SIL_SYSCFG); } |
1da177e4c
|
566 567 |
/** * sil_dev_config - Apply device/host-specific errata fixups |
1da177e4c
|
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
* @dev: Device to be examined * * After the IDENTIFY [PACKET] DEVICE step is complete, and a * device is known to be present, this function is called. * We apply two errata fixups which are specific to Silicon Image, * a Seagate and a Maxtor fixup. * * For certain Seagate devices, we must limit the maximum sectors * to under 8K. * * For certain Maxtor devices, we must not program the drive * beyond udma5. * * Both fixups are unfairly pessimistic. As soon as I get more * information on these errata, I will create a more exhaustive * list, and apply the fixups to only the specific * devices/hosts/firmwares that need it. * * 20040111 - Seagate drives affected by the Mod15Write bug are blacklisted * The Maxtor quirk is in the blacklist, but I'm keeping the original * pessimistic fix for the following reasons... * - There seems to be less info on it, only one device gleaned off the * Windows driver, maybe only one is affected. More info would be greatly * appreciated. * - But then again UDMA5 is hardly anything to complain about */ |
cd0d3bbcd
|
594 |
static void sil_dev_config(struct ata_device *dev) |
1da177e4c
|
595 |
{ |
9af5c9c97
|
596 597 |
struct ata_port *ap = dev->link->ap; int print_info = ap->link.eh_context.i.flags & ATA_EHI_PRINTINFO; |
1da177e4c
|
598 |
unsigned int n, quirks = 0; |
a0cf733b3
|
599 |
unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
1da177e4c
|
600 |
|
a0cf733b3
|
601 |
ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); |
1da177e4c
|
602 |
|
8a60a0712
|
603 |
for (n = 0; sil_blacklist[n].product; n++) |
2e02671da
|
604 |
if (!strcmp(sil_blacklist[n].product, model_num)) { |
1da177e4c
|
605 606 607 |
quirks = sil_blacklist[n].quirk; break; } |
8a60a0712
|
608 |
|
1da177e4c
|
609 |
/* limit requests to 15 sectors */ |
51e9f2ff8
|
610 611 612 |
if (slow_down || ((ap->flags & SIL_FLAG_MOD15WRITE) && (quirks & SIL_QUIRK_MOD15WRITE))) { |
efdaedc44
|
613 |
if (print_info) |
a9a79dfec
|
614 615 616 |
ata_dev_info(dev, "applying Seagate errata fix (mod15write workaround) "); |
b00eec1d5
|
617 |
dev->max_sectors = 15; |
1da177e4c
|
618 619 620 621 622 |
return; } /* limit to udma5 */ if (quirks & SIL_QUIRK_UDMA5MAX) { |
efdaedc44
|
623 |
if (print_info) |
a9a79dfec
|
624 625 626 |
ata_dev_info(dev, "applying Maxtor errata fix %s ", model_num); |
5a5291395
|
627 |
dev->udma_mask &= ATA_UDMA5; |
1da177e4c
|
628 629 630 |
return; } } |
4447d3515
|
631 |
static void sil_init_controller(struct ata_host *host) |
3d8ec9135
|
632 |
{ |
4447d3515
|
633 634 |
struct pci_dev *pdev = to_pci_dev(host->dev); void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR]; |
3d8ec9135
|
635 636 637 638 639 640 641 642 643 |
u8 cls; u32 tmp; int i; /* Initialize FIFO PCI bus arbitration */ cls = sil_get_device_cache_line(pdev); if (cls) { cls >>= 3; cls++; /* cls = (line_size/8)+1 */ |
4447d3515
|
644 |
for (i = 0; i < host->n_ports; i++) |
3d8ec9135
|
645 646 647 |
writew(cls << 8 | cls, mmio_base + sil_port[i].fifo_cfg); } else |
a44fec1fc
|
648 649 650 |
dev_warn(&pdev->dev, "cache line size not set. Driver may not function "); |
3d8ec9135
|
651 652 |
/* Apply R_ERR on DMA activate FIS errata workaround */ |
4447d3515
|
653 |
if (host->ports[0]->flags & SIL_FLAG_RERR_ON_DMA_ACT) { |
3d8ec9135
|
654 |
int cnt; |
4447d3515
|
655 |
for (i = 0, cnt = 0; i < host->n_ports; i++) { |
3d8ec9135
|
656 657 658 659 |
tmp = readl(mmio_base + sil_port[i].sfis_cfg); if ((tmp & 0x3) != 0x01) continue; if (!cnt) |
a44fec1fc
|
660 661 662 |
dev_info(&pdev->dev, "Applying R_ERR on DMA activate FIS errata fix "); |
3d8ec9135
|
663 664 665 666 |
writel(tmp & ~0x3, mmio_base + sil_port[i].sfis_cfg); cnt++; } } |
4447d3515
|
667 |
if (host->n_ports == 4) { |
3d8ec9135
|
668 669 670 671 672 673 674 |
/* flip the magic "make 4 ports work" bit */ tmp = readl(mmio_base + sil_port[2].bmdma); if ((tmp & SIL_INTR_STEERING) == 0) writel(tmp | SIL_INTR_STEERING, mmio_base + sil_port[2].bmdma); } } |
e57db7bde
|
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
static bool sil_broken_system_poweroff(struct pci_dev *pdev) { static const struct dmi_system_id broken_systems[] = { { .ident = "HP Compaq nx6325", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq nx6325"), }, /* PCI slot number of the controller */ .driver_data = (void *)0x12UL, }, { } /* terminate list */ }; const struct dmi_system_id *dmi = dmi_first_match(broken_systems); if (dmi) { unsigned long slot = (unsigned long)dmi->driver_data; /* apply the quirk only to on-board controllers */ return slot == PCI_SLOT(pdev->devfn); } return false; } |
5796d1c4c
|
700 |
static int sil_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
1da177e4c
|
701 |
{ |
4447d3515
|
702 |
int board_id = ent->driver_data; |
e57db7bde
|
703 704 |
struct ata_port_info pi = sil_port_info[board_id]; const struct ata_port_info *ppi[] = { &pi, NULL }; |
4447d3515
|
705 |
struct ata_host *host; |
ea6ba10bb
|
706 |
void __iomem *mmio_base; |
4447d3515
|
707 |
int n_ports, rc; |
1da177e4c
|
708 |
unsigned int i; |
1da177e4c
|
709 |
|
06296a1e6
|
710 |
ata_print_version_once(&pdev->dev, DRV_VERSION); |
1da177e4c
|
711 |
|
4447d3515
|
712 713 714 715 |
/* allocate host */ n_ports = 2; if (board_id == sil_3114) n_ports = 4; |
e57db7bde
|
716 717 718 719 720 721 722 |
if (sil_broken_system_poweroff(pdev)) { pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN | ATA_FLAG_NO_HIBERNATE_SPINDOWN; dev_info(&pdev->dev, "quirky BIOS, skipping spindown " "on poweroff and hibernation "); } |
4447d3515
|
723 724 725 726 727 |
host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); if (!host) return -ENOMEM; /* acquire resources and fill host */ |
24dc5f33e
|
728 |
rc = pcim_enable_device(pdev); |
1da177e4c
|
729 730 |
if (rc) return rc; |
0d5ff5667
|
731 732 |
rc = pcim_iomap_regions(pdev, 1 << SIL_MMIO_BAR, DRV_NAME); if (rc == -EBUSY) |
24dc5f33e
|
733 |
pcim_pin_device(pdev); |
0d5ff5667
|
734 |
if (rc) |
24dc5f33e
|
735 |
return rc; |
4447d3515
|
736 |
host->iomap = pcim_iomap_table(pdev); |
1da177e4c
|
737 738 739 |
rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); if (rc) |
24dc5f33e
|
740 |
return rc; |
1da177e4c
|
741 742 |
rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); if (rc) |
24dc5f33e
|
743 |
return rc; |
1da177e4c
|
744 |
|
4447d3515
|
745 |
mmio_base = host->iomap[SIL_MMIO_BAR]; |
1da177e4c
|
746 |
|
4447d3515
|
747 |
for (i = 0; i < host->n_ports; i++) { |
cbcdd8759
|
748 749 |
struct ata_port *ap = host->ports[i]; struct ata_ioports *ioaddr = &ap->ioaddr; |
4447d3515
|
750 751 752 753 754 755 |
ioaddr->cmd_addr = mmio_base + sil_port[i].tf; ioaddr->altstatus_addr = ioaddr->ctl_addr = mmio_base + sil_port[i].ctl; ioaddr->bmdma_addr = mmio_base + sil_port[i].bmdma; ioaddr->scr_addr = mmio_base + sil_port[i].scr; |
9363c3825
|
756 |
ata_sff_std_ports(ioaddr); |
cbcdd8759
|
757 758 759 |
ata_port_pbar_desc(ap, SIL_MMIO_BAR, -1, "mmio"); ata_port_pbar_desc(ap, SIL_MMIO_BAR, sil_port[i].tf, "tf"); |
1da177e4c
|
760 |
} |
4447d3515
|
761 762 |
/* initialize and activate */ sil_init_controller(host); |
1da177e4c
|
763 |
|
1da177e4c
|
764 |
pci_set_master(pdev); |
4447d3515
|
765 766 |
return ata_host_activate(host, pdev->irq, sil_interrupt, IRQF_SHARED, &sil_sht); |
1da177e4c
|
767 |
} |
281d426c7
|
768 |
#ifdef CONFIG_PM |
afb5a7cb8
|
769 770 |
static int sil_pci_device_resume(struct pci_dev *pdev) { |
cca3974e4
|
771 |
struct ata_host *host = dev_get_drvdata(&pdev->dev); |
553c4aa63
|
772 773 774 775 776 |
int rc; rc = ata_pci_device_do_resume(pdev); if (rc) return rc; |
afb5a7cb8
|
777 |
|
4447d3515
|
778 |
sil_init_controller(host); |
cca3974e4
|
779 |
ata_host_resume(host); |
afb5a7cb8
|
780 781 782 |
return 0; } |
281d426c7
|
783 |
#endif |
afb5a7cb8
|
784 |
|
1da177e4c
|
785 786 |
static int __init sil_init(void) { |
b7887196e
|
787 |
return pci_register_driver(&sil_pci_driver); |
1da177e4c
|
788 789 790 791 792 793 794 795 796 797 |
} static void __exit sil_exit(void) { pci_unregister_driver(&sil_pci_driver); } module_init(sil_init); module_exit(sil_exit); |