sata_nv.c 17 KB

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