sata_sis.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. };
  106. static struct ata_port_info sis_port_info = {
  107. .sht = &sis_sht,
  108. .host_flags = ATA_FLAG_SATA | ATA_FLAG_SATA_RESET |
  109. ATA_FLAG_NO_LEGACY,
  110. .pio_mask = 0x1f,
  111. .mwdma_mask = 0x7,
  112. .udma_mask = 0x7f,
  113. .port_ops = &sis_ops,
  114. };
  115. MODULE_AUTHOR("Uwe Koziolek");
  116. MODULE_DESCRIPTION("low-level driver for Silicon Integratad Systems SATA controller");
  117. MODULE_LICENSE("GPL");
  118. MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
  119. MODULE_VERSION(DRV_VERSION);
  120. static unsigned int get_scr_cfg_addr(unsigned int port_no, unsigned int sc_reg)
  121. {
  122. unsigned int addr = SIS_SCR_BASE + (4 * sc_reg);
  123. if (port_no)
  124. addr += SIS_SATA1_OFS;
  125. return addr;
  126. }
  127. static u32 sis_scr_cfg_read (struct ata_port *ap, unsigned int sc_reg)
  128. {
  129. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  130. unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, sc_reg);
  131. u32 val;
  132. if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
  133. return 0xffffffff;
  134. pci_read_config_dword(pdev, cfg_addr, &val);
  135. return val;
  136. }
  137. static void sis_scr_cfg_write (struct ata_port *ap, unsigned int scr, u32 val)
  138. {
  139. struct pci_dev *pdev = to_pci_dev(ap->host_set->dev);
  140. unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, scr);
  141. if (scr == SCR_ERROR) /* doesn't exist in PCI cfg space */
  142. return;
  143. pci_write_config_dword(pdev, cfg_addr, val);
  144. }
  145. static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg)
  146. {
  147. if (sc_reg > SCR_CONTROL)
  148. return 0xffffffffU;
  149. if (ap->flags & SIS_FLAG_CFGSCR)
  150. return sis_scr_cfg_read(ap, sc_reg);
  151. return inl(ap->ioaddr.scr_addr + (sc_reg * 4));
  152. }
  153. static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
  154. {
  155. if (sc_reg > SCR_CONTROL)
  156. return;
  157. if (ap->flags & SIS_FLAG_CFGSCR)
  158. sis_scr_cfg_write(ap, sc_reg, val);
  159. else
  160. outl(val, ap->ioaddr.scr_addr + (sc_reg * 4));
  161. }
  162. /* move to PCI layer, integrate w/ MSI stuff */
  163. static void pci_enable_intx(struct pci_dev *pdev)
  164. {
  165. u16 pci_command;
  166. pci_read_config_word(pdev, PCI_COMMAND, &pci_command);
  167. if (pci_command & PCI_COMMAND_INTX_DISABLE) {
  168. pci_command &= ~PCI_COMMAND_INTX_DISABLE;
  169. pci_write_config_word(pdev, PCI_COMMAND, pci_command);
  170. }
  171. }
  172. static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
  173. {
  174. struct ata_probe_ent *probe_ent = NULL;
  175. int rc;
  176. u32 genctl;
  177. struct ata_port_info *ppi;
  178. int pci_dev_busy = 0;
  179. rc = pci_enable_device(pdev);
  180. if (rc)
  181. return rc;
  182. rc = pci_request_regions(pdev, DRV_NAME);
  183. if (rc) {
  184. pci_dev_busy = 1;
  185. goto err_out;
  186. }
  187. rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  188. if (rc)
  189. goto err_out_regions;
  190. rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  191. if (rc)
  192. goto err_out_regions;
  193. ppi = &sis_port_info;
  194. probe_ent = ata_pci_init_native_mode(pdev, &ppi);
  195. if (!probe_ent) {
  196. rc = -ENOMEM;
  197. goto err_out_regions;
  198. }
  199. /* check and see if the SCRs are in IO space or PCI cfg space */
  200. pci_read_config_dword(pdev, SIS_GENCTL, &genctl);
  201. if ((genctl & GENCTL_IOMAPPED_SCR) == 0)
  202. probe_ent->host_flags |= SIS_FLAG_CFGSCR;
  203. /* if hardware thinks SCRs are in IO space, but there are
  204. * no IO resources assigned, change to PCI cfg space.
  205. */
  206. if ((!(probe_ent->host_flags & SIS_FLAG_CFGSCR)) &&
  207. ((pci_resource_start(pdev, SIS_SCR_PCI_BAR) == 0) ||
  208. (pci_resource_len(pdev, SIS_SCR_PCI_BAR) < 128))) {
  209. genctl &= ~GENCTL_IOMAPPED_SCR;
  210. pci_write_config_dword(pdev, SIS_GENCTL, genctl);
  211. probe_ent->host_flags |= SIS_FLAG_CFGSCR;
  212. }
  213. if (!(probe_ent->host_flags & SIS_FLAG_CFGSCR)) {
  214. probe_ent->port[0].scr_addr =
  215. pci_resource_start(pdev, SIS_SCR_PCI_BAR);
  216. probe_ent->port[1].scr_addr =
  217. pci_resource_start(pdev, SIS_SCR_PCI_BAR) + 64;
  218. }
  219. pci_set_master(pdev);
  220. pci_enable_intx(pdev);
  221. /* FIXME: check ata_device_add return value */
  222. ata_device_add(probe_ent);
  223. kfree(probe_ent);
  224. return 0;
  225. err_out_regions:
  226. pci_release_regions(pdev);
  227. err_out:
  228. if (!pci_dev_busy)
  229. pci_disable_device(pdev);
  230. return rc;
  231. }
  232. static int __init sis_init(void)
  233. {
  234. return pci_module_init(&sis_pci_driver);
  235. }
  236. static void __exit sis_exit(void)
  237. {
  238. pci_unregister_driver(&sis_pci_driver);
  239. }
  240. module_init(sis_init);
  241. module_exit(sis_exit);