PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/ata/sata_sil.c

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