oak.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Oak Generic NCR5380 driver
  3. *
  4. * Copyright 1995-2002, Russell King
  5. */
  6. #include <linux/module.h>
  7. #include <linux/signal.h>
  8. #include <linux/sched.h>
  9. #include <linux/ioport.h>
  10. #include <linux/delay.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/init.h>
  13. #include <asm/ecard.h>
  14. #include <asm/io.h>
  15. #include <asm/system.h>
  16. #include "../scsi.h"
  17. #include <scsi/scsi_host.h>
  18. #define AUTOSENSE
  19. /*#define PSEUDO_DMA*/
  20. #define OAKSCSI_PUBLIC_RELEASE 1
  21. #define NCR5380_read(reg) oakscsi_read(_instance, reg)
  22. #define NCR5380_write(reg, value) oakscsi_write(_instance, reg, value)
  23. #define NCR5380_intr oakscsi_intr
  24. #define NCR5380_queue_command oakscsi_queue_command
  25. #define NCR5380_proc_info oakscsi_proc_info
  26. #define NCR5380_implementation_fields int port, ctrl
  27. #define NCR5380_local_declare() struct Scsi_Host *_instance
  28. #define NCR5380_setup(instance) _instance = instance
  29. #define BOARD_NORMAL 0
  30. #define BOARD_NCR53C400 1
  31. #include "../NCR5380.h"
  32. #undef START_DMA_INITIATOR_RECEIVE_REG
  33. #define START_DMA_INITIATOR_RECEIVE_REG (7 + 128)
  34. const char * oakscsi_info (struct Scsi_Host *spnt)
  35. {
  36. return "";
  37. }
  38. #define STAT(p) inw(p + 144)
  39. extern void inswb(int from, void *to, int len);
  40. static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *addr,
  41. int len)
  42. {
  43. int iobase = instance->io_port;
  44. printk("writing %p len %d\n",addr, len);
  45. if(!len) return -1;
  46. while(1)
  47. {
  48. int status;
  49. while(((status = STAT(iobase)) & 0x100)==0);
  50. }
  51. }
  52. static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *addr,
  53. int len)
  54. {
  55. int iobase = instance->io_port;
  56. printk("reading %p len %d\n", addr, len);
  57. while(len > 0)
  58. {
  59. int status, timeout;
  60. unsigned long b;
  61. timeout = 0x01FFFFFF;
  62. while(((status = STAT(iobase)) & 0x100)==0)
  63. {
  64. timeout--;
  65. if(status & 0x200 || !timeout)
  66. {
  67. printk("status = %08X\n",status);
  68. return 1;
  69. }
  70. }
  71. if(len >= 128)
  72. {
  73. inswb(iobase + 136, addr, 128);
  74. addr += 128;
  75. len -= 128;
  76. }
  77. else
  78. {
  79. b = (unsigned long) inw(iobase + 136);
  80. *addr ++ = b;
  81. len -= 1;
  82. if(len)
  83. *addr ++ = b>>8;
  84. len -= 1;
  85. }
  86. }
  87. return 0;
  88. }
  89. #define oakscsi_read(instance,reg) (inb((instance)->io_port + (reg)))
  90. #define oakscsi_write(instance,reg,val) (outb((val), (instance)->io_port + (reg)))
  91. #undef STAT
  92. #include "../NCR5380.c"
  93. static struct scsi_host_template oakscsi_template = {
  94. .module = THIS_MODULE,
  95. .proc_info = oakscsi_proc_info,
  96. .name = "Oak 16-bit SCSI",
  97. .info = oakscsi_info,
  98. .queuecommand = oakscsi_queue_command,
  99. .eh_abort_handler = NCR5380_abort,
  100. .eh_bus_reset_handler = NCR5380_bus_reset,
  101. .can_queue = 16,
  102. .this_id = 7,
  103. .sg_tablesize = SG_ALL,
  104. .cmd_per_lun = 2,
  105. .use_clustering = DISABLE_CLUSTERING,
  106. .proc_name = "oakscsi",
  107. };
  108. static int __devinit
  109. oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
  110. {
  111. struct Scsi_Host *host;
  112. int ret = -ENOMEM;
  113. host = scsi_host_alloc(&oakscsi_template, sizeof(struct NCR5380_hostdata));
  114. if (!host)
  115. goto out;
  116. host->io_port = ecard_address(ec, ECARD_MEMC, 0);
  117. host->irq = IRQ_NONE;
  118. host->n_io_port = 255;
  119. ret = -EBUSY;
  120. if (!request_region (host->io_port, host->n_io_port, "Oak SCSI"))
  121. goto unreg;
  122. NCR5380_init(host, 0);
  123. printk("scsi%d: at port 0x%08lx irqs disabled",
  124. host->host_no, host->io_port);
  125. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  126. host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
  127. printk("\nscsi%d:", host->host_no);
  128. NCR5380_print_options(host);
  129. printk("\n");
  130. ret = scsi_add_host(host, &ec->dev);
  131. if (ret)
  132. goto out_release;
  133. scsi_scan_host(host);
  134. goto out;
  135. out_release:
  136. release_region(host->io_port, host->n_io_port);
  137. unreg:
  138. scsi_host_put(host);
  139. out:
  140. return ret;
  141. }
  142. static void __devexit oakscsi_remove(struct expansion_card *ec)
  143. {
  144. struct Scsi_Host *host = ecard_get_drvdata(ec);
  145. ecard_set_drvdata(ec, NULL);
  146. scsi_remove_host(host);
  147. NCR5380_exit(host);
  148. release_region(host->io_port, host->n_io_port);
  149. scsi_host_put(host);
  150. }
  151. static const struct ecard_id oakscsi_cids[] = {
  152. { MANU_OAK, PROD_OAK_SCSI },
  153. { 0xffff, 0xffff }
  154. };
  155. static struct ecard_driver oakscsi_driver = {
  156. .probe = oakscsi_probe,
  157. .remove = __devexit_p(oakscsi_remove),
  158. .id_table = oakscsi_cids,
  159. .drv = {
  160. .name = "oakscsi",
  161. },
  162. };
  163. static int __init oakscsi_init(void)
  164. {
  165. return ecard_register_driver(&oakscsi_driver);
  166. }
  167. static void __exit oakscsi_exit(void)
  168. {
  169. ecard_remove_driver(&oakscsi_driver);
  170. }
  171. module_init(oakscsi_init);
  172. module_exit(oakscsi_exit);
  173. MODULE_AUTHOR("Russell King");
  174. MODULE_DESCRIPTION("Oak SCSI driver");
  175. MODULE_LICENSE("GPL");