sata_nv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * sata_nv.c - NVIDIA nForce SATA
  3. *
  4. * Copyright 2004 NVIDIA Corp. All rights reserved.
  5. * Copyright 2004 Andrew Chew
  6. *
  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; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; see the file COPYING. If not, write to
  20. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. *
  23. * libata documentation is available via 'make {ps|pdf}docs',
  24. * as Documentation/DocBook/libata.*
  25. *
  26. * No hardware documentation available outside of NVIDIA.
  27. * This driver programs the NVIDIA SATA controller in a similar
  28. * fashion as with other PCI IDE BMDMA controllers, with a few
  29. * NV-specific details such as register offsets, SATA phy location,
  30. * hotplug info, etc.
  31. *
  32. * 0.10
  33. * - Fixed spurious interrupts issue seen with the Maxtor 6H500F0 500GB
  34. * drive. Also made the check_hotplug() callbacks return whether there
  35. * was a hotplug interrupt or not. This was not the source of the
  36. * spurious interrupts, but is the right thing to do anyway.
  37. *
  38. * 0.09
  39. * - Fixed bug introduced by 0.08's MCP51 and MCP55 support.
  40. *
  41. * 0.08
  42. * - Added support for MCP51 and MCP55.
  43. *
  44. * 0.07
  45. * - Added support for RAID class code.
  46. *
  47. * 0.06
  48. * - Added generic SATA support by using a pci_device_id that filters on
  49. * the IDE storage class code.
  50. *
  51. * 0.03
  52. * - Fixed a bug where the hotplug handlers for non-CK804/MCP04 were using
  53. * mmio_base, which is only set for the CK804/MCP04 case.
  54. *
  55. * 0.02
  56. * - Added support for CK804 SATA controller.
  57. *
  58. * 0.01
  59. * - Initial revision.
  60. */
  61. #include <linux/config.h>
  62. #include <linux/kernel.h>
  63. #include <linux/module.h>
  64. #include <linux/pci.h>
  65. #include <linux/init.h>
  66. #include <linux/blkdev.h>
  67. #include <linux/delay.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/device.h>
  70. #include <scsi/scsi_host.h>
  71. #include <linux/libata.h>
  72. #define DRV_NAME "sata_nv"
  73. #define DRV_VERSION "0.8"
  74. #define NV_PORTS 2
  75. #define NV_PIO_MASK 0x1f
  76. #define NV_MWDMA_MASK 0x07
  77. #define NV_UDMA_MASK 0x7f
  78. #define NV_PORT0_SCR_REG_OFFSET 0x00
  79. #define NV_PORT1_SCR_REG_OFFSET 0x40
  80. #define NV_INT_STATUS 0x10
  81. #define NV_INT_STATUS_CK804 0x440
  82. #define NV_INT_STATUS_PDEV_INT 0x01
  83. #define NV_INT_STATUS_PDEV_PM 0x02
  84. #define NV_INT_STATUS_PDEV_ADDED 0x04
  85. #define NV_INT_STATUS_PDEV_REMOVED 0x08
  86. #define NV_INT_STATUS_SDEV_INT 0x10
  87. #define NV_INT_STATUS_SDEV_PM 0x20
  88. #define NV_INT_STATUS_SDEV_ADDED 0x40
  89. #define NV_INT_STATUS_SDEV_REMOVED 0x80
  90. #define NV_INT_STATUS_PDEV_HOTPLUG (NV_INT_STATUS_PDEV_ADDED | \
  91. NV_INT_STATUS_PDEV_REMOVED)
  92. #define NV_INT_STATUS_SDEV_HOTPLUG (NV_INT_STATUS_SDEV_ADDED | \
  93. NV_INT_STATUS_SDEV_REMOVED)
  94. #define NV_INT_STATUS_HOTPLUG (NV_INT_STATUS_PDEV_HOTPLUG | \
  95. NV_INT_STATUS_SDEV_HOTPLUG)
  96. #define NV_INT_ENABLE 0x11
  97. #define NV_INT_ENABLE_CK804 0x441
  98. #define NV_INT_ENABLE_PDEV_MASK 0x01
  99. #define NV_INT_ENABLE_PDEV_PM 0x02
  100. #define NV_INT_ENABLE_PDEV_ADDED 0x04
  101. #define NV_INT_ENABLE_PDEV_REMOVED 0x08
  102. #define NV_INT_ENABLE_SDEV_MASK 0x10
  103. #define NV_INT_ENABLE_SDEV_PM 0x20
  104. #define NV_INT_ENABLE_SDEV_ADDED 0x40
  105. #define NV_INT_ENABLE_SDEV_REMOVED 0x80
  106. #define NV_INT_ENABLE_PDEV_HOTPLUG (NV_INT_ENABLE_PDEV_ADDED | \
  107. NV_INT_ENABLE_PDEV_REMOVED)
  108. #define NV_INT_ENABLE_SDEV_HOTPLUG (NV_INT_ENABLE_SDEV_ADDED | \
  109. NV_INT_ENABLE_SDEV_REMOVED)
  110. #define NV_INT_ENABLE_HOTPLUG (NV_INT_ENABLE_PDEV_HOTPLUG | \
  111. NV_INT_ENABLE_SDEV_HOTPLUG)
  112. #define NV_INT_CONFIG 0x12
  113. #define NV_INT_CONFIG_METHD 0x01 // 0 = INT, 1 = SMI
  114. // For PCI config register 20
  115. #define NV_MCP_SATA_CFG_20 0x50
  116. #define NV_MCP_SATA_CFG_20_SATA_SPACE_EN 0x04
  117. static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  118. static irqreturn_t nv_interrupt (int irq, void *dev_instance,
  119. struct pt_regs *regs);
  120. static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg);
  121. static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  122. static void nv_host_stop (struct ata_host_set *host_set);
  123. static void nv_enable_hotplug(struct ata_probe_ent *probe_ent);
  124. static void nv_disable_hotplug(struct ata_host_set *host_set);
  125. static int nv_check_hotplug(struct ata_host_set *host_set);
  126. static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent);
  127. static void nv_disable_hotplug_ck804(struct ata_host_set *host_set);
  128. static int nv_check_hotplug_ck804(struct ata_host_set *host_set);
  129. enum nv_host_type
  130. {
  131. GENERIC,
  132. NFORCE2,
  133. NFORCE3,
  134. CK804
  135. };
  136. static const struct pci_device_id nv_pci_tbl[] = {
  137. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2S_SATA,
  138. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE2 },
  139. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA,
  140. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
  141. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE3S_SATA2,
  142. PCI_ANY_ID, PCI_ANY_ID, 0, 0, NFORCE3 },
  143. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA,
  144. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  145. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_CK804_SATA2,
  146. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  147. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA,
  148. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  149. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SATA2,
  150. PCI_ANY_ID, PCI_ANY_ID, 0, 0, CK804 },
  151. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA,
  152. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  153. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SATA2,
  154. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  155. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA,
  156. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  157. { PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SATA2,
  158. PCI_ANY_ID, PCI_ANY_ID, 0, 0, GENERIC },
  159. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  160. PCI_ANY_ID, PCI_ANY_ID,
  161. PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
  162. { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  163. PCI_ANY_ID, PCI_ANY_ID,
  164. PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
  165. { 0, } /* terminate list */
  166. };
  167. #define NV_HOST_FLAGS_SCR_MMIO 0x00000001
  168. struct nv_host_desc
  169. {
  170. enum nv_host_type host_type;
  171. void (*enable_hotplug)(struct ata_probe_ent *probe_ent);
  172. void (*disable_hotplug)(struct ata_host_set *host_set);
  173. int (*check_hotplug)(struct ata_host_set *host_set);
  174. };
  175. static struct nv_host_desc nv_device_tbl[] = {
  176. {
  177. .host_type = GENERIC,
  178. .enable_hotplug = NULL,
  179. .disable_hotplug= NULL,
  180. .check_hotplug = NULL,
  181. },
  182. {
  183. .host_type = NFORCE2,
  184. .enable_hotplug = nv_enable_hotplug,
  185. .disable_hotplug= nv_disable_hotplug,
  186. .check_hotplug = nv_check_hotplug,
  187. },
  188. {
  189. .host_type = NFORCE3,
  190. .enable_hotplug = nv_enable_hotplug,
  191. .disable_hotplug= nv_disable_hotplug,
  192. .check_hotplug = nv_check_hotplug,
  193. },
  194. { .host_type = CK804,
  195. .enable_hotplug = nv_enable_hotplug_ck804,
  196. .disable_hotplug= nv_disable_hotplug_ck804,
  197. .check_hotplug = nv_check_hotplug_ck804,
  198. },
  199. };
  200. struct nv_host
  201. {
  202. struct nv_host_desc *host_desc;
  203. unsigned long host_flags;
  204. };
  205. static struct pci_driver nv_pci_driver = {
  206. .name = DRV_NAME,
  207. .id_table = nv_pci_tbl,
  208. .probe = nv_init_one,
  209. .remove = ata_pci_remove_one,
  210. };
  211. static struct scsi_host_template nv_sht = {
  212. .module = THIS_MODULE,
  213. .name = DRV_NAME,
  214. .ioctl = ata_scsi_ioctl,
  215. .queuecommand = ata_scsi_queuecmd,
  216. .eh_timed_out = ata_scsi_timed_out,
  217. .eh_strategy_handler = ata_scsi_error,
  218. .can_queue = ATA_DEF_QUEUE,
  219. .this_id = ATA_SHT_THIS_ID,
  220. .sg_tablesize = LIBATA_MAX_PRD,
  221. .max_sectors = ATA_MAX_SECTORS,
  222. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  223. .emulated = ATA_SHT_EMULATED,
  224. .use_clustering = ATA_SHT_USE_CLUSTERING,
  225. .proc_name = DRV_NAME,
  226. .dma_boundary = ATA_DMA_BOUNDARY,
  227. .slave_configure = ata_scsi_slave_config,
  228. .bios_param = ata_std_bios_param,
  229. };
  230. static const struct ata_port_operations nv_ops = {
  231. .port_disable = ata_port_disable,
  232. .tf_load = ata_tf_load,
  233. .tf_read = ata_tf_read,
  234. .exec_command = ata_exec_command,
  235. .check_status = ata_check_status,
  236. .dev_select = ata_std_dev_select,
  237. .phy_reset = sata_phy_reset,
  238. .bmdma_setup = ata_bmdma_setup,
  239. .bmdma_start = ata_bmdma_start,
  240. .bmdma_stop = ata_bmdma_stop,
  241. .bmdma_status = ata_bmdma_status,
  242. .qc_prep = ata_qc_prep,
  243. .qc_issue = ata_qc_issue_prot,
  244. .eng_timeout = ata_eng_timeout,
  245. .irq_handler = nv_interrupt,
  246. .irq_clear = ata_bmdma_irq_clear,
  247. .scr_read = nv_scr_read,
  248. .scr_write = nv_scr_write,
  249. .port_start = ata_port_start,
  250. .port_stop = ata_port_stop,
  251. .host_stop = nv_host_stop,
  252. };
  253. /* FIXME: The hardware provides the necessary SATA PHY controls
  254. * to support ATA_FLAG_SATA_RESET. However, it is currently
  255. * necessary to disable that flag, to solve misdetection problems.
  256. * See http://bugme.osdl.org/show_bug.cgi?id=3352 for more info.
  257. *
  258. * This problem really needs to be investigated further. But in the
  259. * meantime, we avoid ATA_FLAG_SATA_RESET to get people working.
  260. */
  261. static struct ata_port_info nv_port_info = {
  262. .sht = &nv_sht,
  263. .host_flags = ATA_FLAG_SATA |
  264. /* ATA_FLAG_SATA_RESET | */
  265. ATA_FLAG_SRST |
  266. ATA_FLAG_NO_LEGACY,
  267. .pio_mask = NV_PIO_MASK,
  268. .mwdma_mask = NV_MWDMA_MASK,
  269. .udma_mask = NV_UDMA_MASK,
  270. .port_ops = &nv_ops,
  271. };
  272. MODULE_AUTHOR("NVIDIA");
  273. MODULE_DESCRIPTION("low-level driver for NVIDIA nForce SATA controller");
  274. MODULE_LICENSE("GPL");
  275. MODULE_DEVICE_TABLE(pci, nv_pci_tbl);
  276. MODULE_VERSION(DRV_VERSION);
  277. static irqreturn_t nv_interrupt (int irq, void *dev_instance,
  278. struct pt_regs *regs)
  279. {
  280. struct ata_host_set *host_set = dev_instance;
  281. struct nv_host *host = host_set->private_data;
  282. unsigned int i;
  283. unsigned int handled = 0;
  284. unsigned long flags;
  285. spin_lock_irqsave(&host_set->lock, flags);
  286. for (i = 0; i < host_set->n_ports; i++) {
  287. struct ata_port *ap;
  288. ap = host_set->ports[i];
  289. if (ap &&
  290. !(ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) {
  291. struct ata_queued_cmd *qc;
  292. qc = ata_qc_from_tag(ap, ap->active_tag);
  293. if (qc && (!(qc->tf.ctl & ATA_NIEN)))
  294. handled += ata_host_intr(ap, qc);
  295. else
  296. // No request pending? Clear interrupt status
  297. // anyway, in case there's one pending.
  298. ap->ops->check_status(ap);
  299. }
  300. }
  301. if (host->host_desc->check_hotplug)
  302. handled += host->host_desc->check_hotplug(host_set);
  303. spin_unlock_irqrestore(&host_set->lock, flags);
  304. return IRQ_RETVAL(handled);
  305. }
  306. static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
  307. {
  308. struct ata_host_set *host_set = ap->host_set;
  309. struct nv_host *host = host_set->private_data;
  310. if (sc_reg > SCR_CONTROL)
  311. return 0xffffffffU;
  312. if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
  313. return readl((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  314. else
  315. return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
  316. }
  317. static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
  318. {
  319. struct ata_host_set *host_set = ap->host_set;
  320. struct nv_host *host = host_set->private_data;
  321. if (sc_reg > SCR_CONTROL)
  322. return;
  323. if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
  324. writel(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4));
  325. else
  326. outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
  327. }
  328. static void nv_host_stop (struct ata_host_set *host_set)
  329. {
  330. struct nv_host *host = host_set->private_data;
  331. struct pci_dev *pdev = to_pci_dev(host_set->dev);
  332. // Disable hotplug event interrupts.
  333. if (host->host_desc->disable_hotplug)
  334. host->host_desc->disable_hotplug(host_set);
  335. kfree(host);
  336. if (host_set->mmio_base)
  337. pci_iounmap(pdev, host_set->mmio_base);
  338. }
  339. static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  340. {
  341. static int printed_version = 0;
  342. struct nv_host *host;
  343. struct ata_port_info *ppi;
  344. struct ata_probe_ent *probe_ent;
  345. int pci_dev_busy = 0;
  346. int rc;
  347. u32 bar;
  348. // Make sure this is a SATA controller by counting the number of bars
  349. // (NVIDIA SATA controllers will always have six bars). Otherwise,
  350. // it's an IDE controller and we ignore it.
  351. for (bar=0; bar<6; bar++)
  352. if (pci_resource_start(pdev, bar) == 0)
  353. return -ENODEV;
  354. if (!printed_version++)
  355. dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  356. rc = pci_enable_device(pdev);
  357. if (rc)
  358. goto err_out;
  359. rc = pci_request_regions(pdev, DRV_NAME);
  360. if (rc) {
  361. pci_dev_busy = 1;
  362. goto err_out_disable;
  363. }
  364. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  365. if (rc)
  366. goto err_out_regions;
  367. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  368. if (rc)
  369. goto err_out_regions;
  370. rc = -ENOMEM;
  371. ppi = &nv_port_info;
  372. probe_ent = ata_pci_init_native_mode(pdev, &ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
  373. if (!probe_ent)
  374. goto err_out_regions;
  375. host = kmalloc(sizeof(struct nv_host), GFP_KERNEL);
  376. if (!host)
  377. goto err_out_free_ent;
  378. memset(host, 0, sizeof(struct nv_host));
  379. host->host_desc = &nv_device_tbl[ent->driver_data];
  380. probe_ent->private_data = host;
  381. if (pci_resource_flags(pdev, 5) & IORESOURCE_MEM)
  382. host->host_flags |= NV_HOST_FLAGS_SCR_MMIO;
  383. if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO) {
  384. unsigned long base;
  385. probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
  386. if (probe_ent->mmio_base == NULL) {
  387. rc = -EIO;
  388. goto err_out_free_host;
  389. }
  390. base = (unsigned long)probe_ent->mmio_base;
  391. probe_ent->port[0].scr_addr =
  392. base + NV_PORT0_SCR_REG_OFFSET;
  393. probe_ent->port[1].scr_addr =
  394. base + NV_PORT1_SCR_REG_OFFSET;
  395. } else {
  396. probe_ent->port[0].scr_addr =
  397. pci_resource_start(pdev, 5) | NV_PORT0_SCR_REG_OFFSET;
  398. probe_ent->port[1].scr_addr =
  399. pci_resource_start(pdev, 5) | NV_PORT1_SCR_REG_OFFSET;
  400. }
  401. pci_set_master(pdev);
  402. rc = ata_device_add(probe_ent);
  403. if (rc != NV_PORTS)
  404. goto err_out_iounmap;
  405. // Enable hotplug event interrupts.
  406. if (host->host_desc->enable_hotplug)
  407. host->host_desc->enable_hotplug(probe_ent);
  408. kfree(probe_ent);
  409. return 0;
  410. err_out_iounmap:
  411. if (host->host_flags & NV_HOST_FLAGS_SCR_MMIO)
  412. pci_iounmap(pdev, probe_ent->mmio_base);
  413. err_out_free_host:
  414. kfree(host);
  415. err_out_free_ent:
  416. kfree(probe_ent);
  417. err_out_regions:
  418. pci_release_regions(pdev);
  419. err_out_disable:
  420. if (!pci_dev_busy)
  421. pci_disable_device(pdev);
  422. err_out:
  423. return rc;
  424. }
  425. static void nv_enable_hotplug(struct ata_probe_ent *probe_ent)
  426. {
  427. u8 intr_mask;
  428. outb(NV_INT_STATUS_HOTPLUG,
  429. probe_ent->port[0].scr_addr + NV_INT_STATUS);
  430. intr_mask = inb(probe_ent->port[0].scr_addr + NV_INT_ENABLE);
  431. intr_mask |= NV_INT_ENABLE_HOTPLUG;
  432. outb(intr_mask, probe_ent->port[0].scr_addr + NV_INT_ENABLE);
  433. }
  434. static void nv_disable_hotplug(struct ata_host_set *host_set)
  435. {
  436. u8 intr_mask;
  437. intr_mask = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
  438. intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
  439. outb(intr_mask, host_set->ports[0]->ioaddr.scr_addr + NV_INT_ENABLE);
  440. }
  441. static int nv_check_hotplug(struct ata_host_set *host_set)
  442. {
  443. u8 intr_status;
  444. intr_status = inb(host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
  445. // Clear interrupt status.
  446. outb(0xff, host_set->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
  447. if (intr_status & NV_INT_STATUS_HOTPLUG) {
  448. if (intr_status & NV_INT_STATUS_PDEV_ADDED)
  449. printk(KERN_WARNING "nv_sata: "
  450. "Primary device added\n");
  451. if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
  452. printk(KERN_WARNING "nv_sata: "
  453. "Primary device removed\n");
  454. if (intr_status & NV_INT_STATUS_SDEV_ADDED)
  455. printk(KERN_WARNING "nv_sata: "
  456. "Secondary device added\n");
  457. if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
  458. printk(KERN_WARNING "nv_sata: "
  459. "Secondary device removed\n");
  460. return 1;
  461. }
  462. return 0;
  463. }
  464. static void nv_enable_hotplug_ck804(struct ata_probe_ent *probe_ent)
  465. {
  466. struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
  467. u8 intr_mask;
  468. u8 regval;
  469. pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
  470. regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
  471. pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
  472. writeb(NV_INT_STATUS_HOTPLUG, probe_ent->mmio_base + NV_INT_STATUS_CK804);
  473. intr_mask = readb(probe_ent->mmio_base + NV_INT_ENABLE_CK804);
  474. intr_mask |= NV_INT_ENABLE_HOTPLUG;
  475. writeb(intr_mask, probe_ent->mmio_base + NV_INT_ENABLE_CK804);
  476. }
  477. static void nv_disable_hotplug_ck804(struct ata_host_set *host_set)
  478. {
  479. struct pci_dev *pdev = to_pci_dev(host_set->dev);
  480. u8 intr_mask;
  481. u8 regval;
  482. intr_mask = readb(host_set->mmio_base + NV_INT_ENABLE_CK804);
  483. intr_mask &= ~(NV_INT_ENABLE_HOTPLUG);
  484. writeb(intr_mask, host_set->mmio_base + NV_INT_ENABLE_CK804);
  485. pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
  486. regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
  487. pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
  488. }
  489. static int nv_check_hotplug_ck804(struct ata_host_set *host_set)
  490. {
  491. u8 intr_status;
  492. intr_status = readb(host_set->mmio_base + NV_INT_STATUS_CK804);
  493. // Clear interrupt status.
  494. writeb(0xff, host_set->mmio_base + NV_INT_STATUS_CK804);
  495. if (intr_status & NV_INT_STATUS_HOTPLUG) {
  496. if (intr_status & NV_INT_STATUS_PDEV_ADDED)
  497. printk(KERN_WARNING "nv_sata: "
  498. "Primary device added\n");
  499. if (intr_status & NV_INT_STATUS_PDEV_REMOVED)
  500. printk(KERN_WARNING "nv_sata: "
  501. "Primary device removed\n");
  502. if (intr_status & NV_INT_STATUS_SDEV_ADDED)
  503. printk(KERN_WARNING "nv_sata: "
  504. "Secondary device added\n");
  505. if (intr_status & NV_INT_STATUS_SDEV_REMOVED)
  506. printk(KERN_WARNING "nv_sata: "
  507. "Secondary device removed\n");
  508. return 1;
  509. }
  510. return 0;
  511. }
  512. static int __init nv_init(void)
  513. {
  514. return pci_module_init(&nv_pci_driver);
  515. }
  516. static void __exit nv_exit(void)
  517. {
  518. pci_unregister_driver(&nv_pci_driver);
  519. }
  520. module_init(nv_init);
  521. module_exit(nv_exit);