sata_sis.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. * sata_sis.c - Silicon Integrated Systems SATA
  3. *
  4. * Maintained by: Uwe Koziolek
  5. * Please ALWAYS copy linux-ide@vger.kernel.org
  6. * on emails.
  7. *
  8. * Copyright 2004 Uwe Koziolek
  9. *
  10. * The contents of this file are subject to the Open
  11. * Software License version 1.1 that can be found at
  12. * http://www.opensource.org/licenses/osl-1.1.txt and is included herein
  13. * by reference.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms
  16. * of the GNU General Public License version 2 (the "GPL") as distributed
  17. * in the kernel source COPYING file, in which case the provisions of
  18. * the GPL are applicable instead of the above. If you wish to allow
  19. * the use of your version of this file only under the terms of the
  20. * GPL and not to allow others to use your version of this file under
  21. * the OSL, indicate your decision by deleting the provisions above and
  22. * replace them with the notice and other provisions required by the GPL.
  23. * If you do not delete the provisions above, a recipient may use your
  24. * version of this file under either the OSL or the GPL.
  25. *
  26. */
  27. #include <linux/config.h>
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/pci.h>
  31. #include <linux/init.h>
  32. #include <linux/blkdev.h>
  33. #include <linux/delay.h>
  34. #include <linux/interrupt.h>
  35. #include "scsi.h"
  36. #include <scsi/scsi_host.h>
  37. #include <linux/libata.h>
  38. #define DRV_NAME "sata_sis"
  39. #define DRV_VERSION "0.5"
  40. enum {
  41. sis_180 = 0,
  42. SIS_SCR_PCI_BAR = 5,
  43. /* PCI configuration registers */
  44. SIS_GENCTL = 0x54, /* IDE General Control register */
  45. SIS_SCR_BASE = 0xc0, /* sata0 phy SCR registers */
  46. SIS_SATA1_OFS = 0x10, /* offset from sata0->sata1 phy regs */
  47. /* random bits */
  48. SIS_FLAG_CFGSCR = (1 << 30), /* host flag: SCRs via PCI cfg */
  49. GENCTL_IOMAPPED_SCR = (1 << 26), /* if set, SCRs are in IO space */
  50. };
  51. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
  52. static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg);
  53. static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
  54. static struct pci_device_id sis_pci_tbl[] = {
  55. { PCI_VENDOR_ID_SI, 0x180, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sis_180 },
  56. { PCI_VENDOR_ID_SI, 0x181, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sis_180 },
  57. { } /* terminate list */
  58. };
  59. static struct pci_driver sis_pci_driver = {
  60. .name = DRV_NAME,
  61. .id_table = sis_pci_tbl,
  62. .probe = sis_init_one,
  63. .remove = ata_pci_remove_one,
  64. };
  65. static Scsi_Host_Template sis_sht = {
  66. .module = THIS_MODULE,
  67. .name = DRV_NAME,
  68. .ioctl = ata_scsi_ioctl,
  69. .queuecommand = ata_scsi_queuecmd,
  70. .eh_strategy_handler = ata_scsi_error,
  71. .can_queue = ATA_DEF_QUEUE,
  72. .this_id = ATA_SHT_THIS_ID,
  73. .sg_tablesize = ATA_MAX_PRD,
  74. .max_sectors = ATA_MAX_SECTORS,
  75. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  76. .emulated = ATA_SHT_EMULATED,
  77. .use_clustering = ATA_SHT_USE_CLUSTERING,
  78. .proc_name = DRV_NAME,
  79. .dma_boundary = ATA_DMA_BOUNDARY,
  80. .slave_configure = ata_scsi_slave_config,
  81. .bios_param = ata_std_bios_param,
  82. .ordered_flush = 1,
  83. };
  84. static struct ata_port_operations sis_ops = {
  85. .port_disable = ata_port_disable,
  86. .tf_load = ata_tf_load,
  87. .tf_read = ata_tf_read,
  88. .check_status = ata_check_status,
  89. .exec_command = ata_exec_command,
  90. .dev_select = ata_std_dev_select,
  91. .phy_reset = sata_phy_reset,
  92. .bmdma_setup = ata_bmdma_setup,
  93. .bmdma_start = ata_bmdma_start,
  94. .bmdma_stop = ata_bmdma_stop,
  95. .bmdma_status = ata_bmdma_status,
  96. .qc_prep = ata_qc_prep,
  97. .qc_issue = ata_qc_issue_prot,
  98. .eng_timeout = ata_eng_timeout,
  99. .irq_handler = ata_interrupt,
  100. .irq_clear = ata_bmdma_irq_clear,
  101. .scr_read = sis_scr_read,
  102. .scr_write = sis_scr_write,
  103. .port_start = ata_port_start,
  104. .port_stop = ata_port_stop,
  105. .host_stop = ata_host_stop,
  106. };
  107. static struct ata_port_info sis_port_info = {
  108. .sht = &sis_sht,
  109. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SATA_RESET |
  110. ATA_FLAG_NO_LEGACY,
  111. .pio_mask = 0x1f,
  112. .mwdma_mask = 0x7,
  113. .udma_mask = 0x7f,
  114. .port_ops = &sis_ops,
  115. };
  116. MODULE_AUTHOR("Uwe Koziolek");
  117. MODULE_DESCRIPTION("low-level driver for Silicon Integratad Systems SATA controller");
  118. MODULE_LICENSE("GPL");
  119. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  120. MODULE_VERSION(DRV_VERSION);
  121. static unsigned int get_scr_cfg_addr(unsigned int port_no, unsigned int sc_reg)
  122. {
  123. unsigned int addr = SIS_SCR_BASE + (4 * sc_reg);
  124. if (port_no)
  125. addr += SIS_SATA1_OFS;
  126. return addr;
  127. }
  128. static u32 sis_scr_cfg_read (struct ata_port *ap, unsigned int sc_reg)
  129. {
  130. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  131. unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, sc_reg);
  132. u32 val;
  133. if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
  134. return 0xffffffff;
  135. pci_read_config_dword(pdev, cfg_addr, &val);
  136. return val;
  137. }
  138. static void sis_scr_cfg_write (struct ata_port *ap, unsigned int scr, u32 val)
  139. {
  140. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  141. unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, scr);
  142. if (scr == SCR_ERROR) /* doesn't exist in PCI cfg space */
  143. return;
  144. pci_write_config_dword(pdev, cfg_addr, val);
  145. }
  146. static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg)
  147. {
  148. if (sc_reg > SCR_CONTROL)
  149. return 0xffffffffU;
  150. if (ap->flags & SIS_FLAG_CFGSCR)
  151. return sis_scr_cfg_read(ap, sc_reg);
  152. return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
  153. }
  154. static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
  155. {
  156. if (sc_reg > SCR_CONTROL)
  157. return;
  158. if (ap->flags & SIS_FLAG_CFGSCR)
  159. sis_scr_cfg_write(ap, sc_reg, val);
  160. else
  161. outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
  162. }
  163. /* move to PCI layer, integrate w/ MSI stuff */
  164. static void pci_enable_intx(struct pci_dev *pdev)
  165. {
  166. u16 pci_command;
  167. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  168. if (pci_command & PCI_COMMAND_INTX_DISABLE) {
  169. pci_command &= ~PCI_COMMAND_INTX_DISABLE;
  170. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  171. }
  172. }
  173. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  174. {
  175. struct ata_probe_ent *probe_ent = NULL;
  176. int rc;
  177. u32 genctl;
  178. struct ata_port_info *ppi;
  179. int pci_dev_busy = 0;
  180. rc = pci_enable_device(pdev);
  181. if (rc)
  182. return rc;
  183. rc = pci_request_regions(pdev, DRV_NAME);
  184. if (rc) {
  185. pci_dev_busy = 1;
  186. goto err_out;
  187. }
  188. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  189. if (rc)
  190. goto err_out_regions;
  191. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  192. if (rc)
  193. goto err_out_regions;
  194. ppi = &sis_port_info;
  195. probe_ent = ata_pci_init_native_mode(pdev, &ppi);
  196. if (!probe_ent) {
  197. rc = -ENOMEM;
  198. goto err_out_regions;
  199. }
  200. /* check and see if the SCRs are in IO space or PCI cfg space */
  201. pci_read_config_dword(pdev, SIS_GENCTL, &genctl);
  202. if ((genctl & GENCTL_IOMAPPED_SCR) == 0)
  203. probe_ent->host_flags |= SIS_FLAG_CFGSCR;
  204. /* if hardware thinks SCRs are in IO space, but there are
  205. * no IO resources assigned, change to PCI cfg space.
  206. */
  207. if ((!(probe_ent->host_flags & SIS_FLAG_CFGSCR)) &&
  208. ((pci_resource_start(pdev, SIS_SCR_PCI_BAR) == 0) ||
  209. (pci_resource_len(pdev, SIS_SCR_PCI_BAR) < 128))) {
  210. genctl &= ~GENCTL_IOMAPPED_SCR;
  211. pci_write_config_dword(pdev, SIS_GENCTL, genctl);
  212. probe_ent->host_flags |= SIS_FLAG_CFGSCR;
  213. }
  214. if (!(probe_ent->host_flags & SIS_FLAG_CFGSCR)) {
  215. probe_ent->port[0].scr_addr =
  216. pci_resource_start(pdev, SIS_SCR_PCI_BAR);
  217. probe_ent->port[1].scr_addr =
  218. pci_resource_start(pdev, SIS_SCR_PCI_BAR) + 64;
  219. }
  220. pci_set_master(pdev);
  221. pci_enable_intx(pdev);
  222. /* FIXME: check ata_device_add return value */
  223. ata_device_add(probe_ent);
  224. kfree(probe_ent);
  225. return 0;
  226. err_out_regions:
  227. pci_release_regions(pdev);
  228. err_out:
  229. if (!pci_dev_busy)
  230. pci_disable_device(pdev);
  231. return rc;
  232. }
  233. static int __init sis_init(void)
  234. {
  235. return pci_module_init(&sis_pci_driver);
  236. }
  237. static void __exit sis_exit(void)
  238. {
  239. pci_unregister_driver(&sis_pci_driver);
  240. }
  241. module_init(sis_init);
  242. module_exit(sis_exit);