sata_nv.c 16 KB

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