sata_nv.c 17 KB

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