ata_generic.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * ata_generic.c - Generic PATA/SATA controller driver.
  3. * Copyright 2005 Red Hat Inc <alan@redhat.com>, all rights reserved.
  4. *
  5. * Elements from ide/pci/generic.c
  6. * Copyright (C) 2001-2002 Andre Hedrick <andre@linux-ide.org>
  7. * Portions (C) Copyright 2002 Red Hat Inc <alan@redhat.com>
  8. *
  9. * May be copied or modified under the terms of the GNU General Public License
  10. *
  11. * Driver for PCI IDE interfaces implementing the standard bus mastering
  12. * interface functionality. This assumes the BIOS did the drive set up and
  13. * tuning for us. By default we do not grab all IDE class devices as they
  14. * may have other drivers or need fixups to avoid problems. Instead we keep
  15. * a default list of stuff without documentation/driver that appears to
  16. * work.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/delay.h>
  24. #include <scsi/scsi_host.h>
  25. #include <linux/libata.h>
  26. #define DRV_NAME "ata_generic"
  27. #define DRV_VERSION "0.2.10"
  28. /*
  29. * A generic parallel ATA driver using libata
  30. */
  31. /**
  32. * generic_pre_reset - probe begin
  33. * @ap: ATA port
  34. *
  35. * Set up cable type and use generic probe init
  36. */
  37. static int generic_pre_reset(struct ata_port *ap)
  38. {
  39. ap->cbl = ATA_CBL_PATA80;
  40. return ata_std_prereset(ap);
  41. }
  42. /**
  43. * generic_error_handler - Probe specified port on PATA host controller
  44. * @ap: Port to probe
  45. * @classes:
  46. *
  47. * LOCKING:
  48. * None (inherited from caller).
  49. */
  50. static void generic_error_handler(struct ata_port *ap)
  51. {
  52. ata_bmdma_drive_eh(ap, generic_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
  53. }
  54. /**
  55. * generic_set_mode - mode setting
  56. * @ap: interface to set up
  57. * @unused: returned device on error
  58. *
  59. * Use a non standard set_mode function. We don't want to be tuned.
  60. * The BIOS configured everything. Our job is not to fiddle. We
  61. * read the dma enabled bits from the PCI configuration of the device
  62. * and respect them.
  63. */
  64. static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
  65. {
  66. int dma_enabled = 0;
  67. int i;
  68. /* Bits 5 and 6 indicate if DMA is active on master/slave */
  69. if (ap->ioaddr.bmdma_addr)
  70. dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
  71. for (i = 0; i < ATA_MAX_DEVICES; i++) {
  72. struct ata_device *dev = &ap->device[i];
  73. if (ata_dev_ready(dev)) {
  74. /* We don't really care */
  75. dev->pio_mode = XFER_PIO_0;
  76. dev->dma_mode = XFER_MW_DMA_0;
  77. /* We do need the right mode information for DMA or PIO
  78. and this comes from the current configuration flags */
  79. if (dma_enabled & (1 << (5 + i))) {
  80. dev->xfer_mode = XFER_MW_DMA_0;
  81. dev->xfer_shift = ATA_SHIFT_MWDMA;
  82. dev->flags &= ~ATA_DFLAG_PIO;
  83. } else {
  84. dev->xfer_mode = XFER_PIO_0;
  85. dev->xfer_shift = ATA_SHIFT_PIO;
  86. dev->flags |= ATA_DFLAG_PIO;
  87. }
  88. }
  89. }
  90. return 0;
  91. }
  92. static struct scsi_host_template generic_sht = {
  93. .module = THIS_MODULE,
  94. .name = DRV_NAME,
  95. .ioctl = ata_scsi_ioctl,
  96. .queuecommand = ata_scsi_queuecmd,
  97. .can_queue = ATA_DEF_QUEUE,
  98. .this_id = ATA_SHT_THIS_ID,
  99. .sg_tablesize = LIBATA_MAX_PRD,
  100. .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
  101. .emulated = ATA_SHT_EMULATED,
  102. .use_clustering = ATA_SHT_USE_CLUSTERING,
  103. .proc_name = DRV_NAME,
  104. .dma_boundary = ATA_DMA_BOUNDARY,
  105. .slave_configure = ata_scsi_slave_config,
  106. .slave_destroy = ata_scsi_slave_destroy,
  107. .bios_param = ata_std_bios_param,
  108. .resume = ata_scsi_device_resume,
  109. .suspend = ata_scsi_device_suspend,
  110. };
  111. static struct ata_port_operations generic_port_ops = {
  112. .set_mode = generic_set_mode,
  113. .port_disable = ata_port_disable,
  114. .tf_load = ata_tf_load,
  115. .tf_read = ata_tf_read,
  116. .check_status = ata_check_status,
  117. .exec_command = ata_exec_command,
  118. .dev_select = ata_std_dev_select,
  119. .bmdma_setup = ata_bmdma_setup,
  120. .bmdma_start = ata_bmdma_start,
  121. .bmdma_stop = ata_bmdma_stop,
  122. .bmdma_status = ata_bmdma_status,
  123. .data_xfer = ata_data_xfer,
  124. .freeze = ata_bmdma_freeze,
  125. .thaw = ata_bmdma_thaw,
  126. .error_handler = generic_error_handler,
  127. .post_internal_cmd = ata_bmdma_post_internal_cmd,
  128. .qc_prep = ata_qc_prep,
  129. .qc_issue = ata_qc_issue_prot,
  130. .irq_handler = ata_interrupt,
  131. .irq_clear = ata_bmdma_irq_clear,
  132. .irq_on = ata_irq_on,
  133. .irq_ack = ata_irq_ack,
  134. .port_start = ata_port_start,
  135. };
  136. static int all_generic_ide; /* Set to claim all devices */
  137. /**
  138. * ata_generic_init - attach generic IDE
  139. * @dev: PCI device found
  140. * @id: match entry
  141. *
  142. * Called each time a matching IDE interface is found. We check if the
  143. * interface is one we wish to claim and if so we perform any chip
  144. * specific hacks then let the ATA layer do the heavy lifting.
  145. */
  146. static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
  147. {
  148. u16 command;
  149. static struct ata_port_info info = {
  150. .sht = &generic_sht,
  151. .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
  152. .pio_mask = 0x1f,
  153. .mwdma_mask = 0x07,
  154. .udma_mask = 0x3f,
  155. .port_ops = &generic_port_ops
  156. };
  157. static struct ata_port_info *port_info[2] = { &info, &info };
  158. /* Don't use the generic entry unless instructed to do so */
  159. if (id->driver_data == 1 && all_generic_ide == 0)
  160. return -ENODEV;
  161. /* Devices that need care */
  162. if (dev->vendor == PCI_VENDOR_ID_UMC &&
  163. dev->device == PCI_DEVICE_ID_UMC_UM8886A &&
  164. (!(PCI_FUNC(dev->devfn) & 1)))
  165. return -ENODEV;
  166. if (dev->vendor == PCI_VENDOR_ID_OPTI &&
  167. dev->device == PCI_DEVICE_ID_OPTI_82C558 &&
  168. (!(PCI_FUNC(dev->devfn) & 1)))
  169. return -ENODEV;
  170. /* Don't re-enable devices in generic mode or we will break some
  171. motherboards with disabled and unused IDE controllers */
  172. pci_read_config_word(dev, PCI_COMMAND, &command);
  173. if (!(command & PCI_COMMAND_IO))
  174. return -ENODEV;
  175. if (dev->vendor == PCI_VENDOR_ID_AL)
  176. ata_pci_clear_simplex(dev);
  177. return ata_pci_init_one(dev, port_info, 2);
  178. }
  179. static struct pci_device_id ata_generic[] = {
  180. { PCI_DEVICE(PCI_VENDOR_ID_PCTECH, PCI_DEVICE_ID_PCTECH_SAMURAI_IDE), },
  181. { PCI_DEVICE(PCI_VENDOR_ID_HOLTEK, PCI_DEVICE_ID_HOLTEK_6565), },
  182. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8673F), },
  183. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886A), },
  184. { PCI_DEVICE(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF), },
  185. { PCI_DEVICE(PCI_VENDOR_ID_HINT, PCI_DEVICE_ID_HINT_VXPROII_IDE), },
  186. { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C561), },
  187. { PCI_DEVICE(PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C558), },
  188. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO), },
  189. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_1), },
  190. { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA,PCI_DEVICE_ID_TOSHIBA_PICCOLO_2), },
  191. /* Must come last. If you add entries adjust this table appropriately */
  192. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE << 8, 0xFFFFFF00UL, 1},
  193. { 0, },
  194. };
  195. static struct pci_driver ata_generic_pci_driver = {
  196. .name = DRV_NAME,
  197. .id_table = ata_generic,
  198. .probe = ata_generic_init_one,
  199. .remove = ata_pci_remove_one,
  200. .suspend = ata_pci_device_suspend,
  201. .resume = ata_pci_device_resume,
  202. };
  203. static int __init ata_generic_init(void)
  204. {
  205. return pci_register_driver(&ata_generic_pci_driver);
  206. }
  207. static void __exit ata_generic_exit(void)
  208. {
  209. pci_unregister_driver(&ata_generic_pci_driver);
  210. }
  211. MODULE_AUTHOR("Alan Cox");
  212. MODULE_DESCRIPTION("low-level driver for generic ATA");
  213. MODULE_LICENSE("GPL");
  214. MODULE_DEVICE_TABLE(pci, ata_generic);
  215. MODULE_VERSION(DRV_VERSION);
  216. module_init(ata_generic_init);
  217. module_exit(ata_generic_exit);
  218. module_param(all_generic_ide, int, 0);