ecoscsi.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #define AUTOSENSE
  2. /* #define PSEUDO_DMA */
  3. /*
  4. * EcoSCSI Generic NCR5380 driver
  5. *
  6. * Copyright 1995, Russell King
  7. *
  8. * ALPHA RELEASE 1.
  9. *
  10. * For more information, please consult
  11. *
  12. * NCR 5380 Family
  13. * SCSI Protocol Controller
  14. * Databook
  15. *
  16. * NCR Microelectronics
  17. * 1635 Aeroplaza Drive
  18. * Colorado Springs, CO 80916
  19. * 1+ (719) 578-3400
  20. * 1+ (800) 334-5454
  21. */
  22. #include <linux/module.h>
  23. #include <linux/signal.h>
  24. #include <linux/sched.h>
  25. #include <linux/ioport.h>
  26. #include <linux/delay.h>
  27. #include <linux/init.h>
  28. #include <linux/blkdev.h>
  29. #include <asm/io.h>
  30. #include <asm/system.h>
  31. #include "../scsi.h"
  32. #include <scsi/scsi_host.h>
  33. #define NCR5380_implementation_fields int port, ctrl
  34. #define NCR5380_local_declare() struct Scsi_Host *_instance
  35. #define NCR5380_setup(instance) _instance = instance
  36. #define NCR5380_read(reg) ecoscsi_read(_instance, reg)
  37. #define NCR5380_write(reg, value) ecoscsi_write(_instance, reg, value)
  38. #define NCR5380_intr ecoscsi_intr
  39. #define NCR5380_queue_command ecoscsi_queue_command
  40. #define NCR5380_proc_info ecoscsi_proc_info
  41. #include "../NCR5380.h"
  42. #define ECOSCSI_PUBLIC_RELEASE 1
  43. static char ecoscsi_read(struct Scsi_Host *instance, int reg)
  44. {
  45. int iobase = instance->io_port;
  46. outb(reg | 8, iobase);
  47. return inb(iobase + 1);
  48. }
  49. static void ecoscsi_write(struct Scsi_Host *instance, int reg, int value)
  50. {
  51. int iobase = instance->io_port;
  52. outb(reg | 8, iobase);
  53. outb(value, iobase + 1);
  54. }
  55. /*
  56. * Function : ecoscsi_setup(char *str, int *ints)
  57. *
  58. * Purpose : LILO command line initialization of the overrides array,
  59. *
  60. * Inputs : str - unused, ints - array of integer parameters with ints[0]
  61. * equal to the number of ints.
  62. *
  63. */
  64. void ecoscsi_setup(char *str, int *ints)
  65. {
  66. }
  67. const char * ecoscsi_info (struct Scsi_Host *spnt)
  68. {
  69. return "";
  70. }
  71. #if 0
  72. #define STAT(p) inw(p + 144)
  73. static inline int NCR5380_pwrite(struct Scsi_Host *host, unsigned char *addr,
  74. int len)
  75. {
  76. int iobase = host->io_port;
  77. printk("writing %p len %d\n",addr, len);
  78. if(!len) return -1;
  79. while(1)
  80. {
  81. int status;
  82. while(((status = STAT(iobase)) & 0x100)==0);
  83. }
  84. }
  85. static inline int NCR5380_pread(struct Scsi_Host *host, unsigned char *addr,
  86. int len)
  87. {
  88. int iobase = host->io_port;
  89. int iobase2= host->io_port + 0x100;
  90. unsigned char *start = addr;
  91. int s;
  92. printk("reading %p len %d\n",addr, len);
  93. outb(inb(iobase + 128), iobase + 135);
  94. while(len > 0)
  95. {
  96. int status,b,i, timeout;
  97. timeout = 0x07FFFFFF;
  98. while(((status = STAT(iobase)) & 0x100)==0)
  99. {
  100. timeout--;
  101. if(status & 0x200 || !timeout)
  102. {
  103. printk("status = %p\n",status);
  104. outb(0, iobase + 135);
  105. return 1;
  106. }
  107. }
  108. if(len >= 128)
  109. {
  110. for(i=0; i<64; i++)
  111. {
  112. b = inw(iobase + 136);
  113. *addr++ = b;
  114. *addr++ = b>>8;
  115. }
  116. len -= 128;
  117. }
  118. else
  119. {
  120. b = inw(iobase + 136);
  121. *addr ++ = b;
  122. len -= 1;
  123. if(len)
  124. *addr ++ = b>>8;
  125. len -= 1;
  126. }
  127. }
  128. outb(0, iobase + 135);
  129. printk("first bytes = %02X %02X %02X %20X %02X %02X %02X\n",*start, start[1], start[2], start[3], start[4], start[5], start[6]);
  130. return 1;
  131. }
  132. #endif
  133. #undef STAT
  134. #define BOARD_NORMAL 0
  135. #define BOARD_NCR53C400 1
  136. #include "../NCR5380.c"
  137. static struct scsi_host_template ecoscsi_template = {
  138. .module = THIS_MODULE,
  139. .name = "Serial Port EcoSCSI NCR5380",
  140. .proc_name = "ecoscsi",
  141. .info = ecoscsi_info,
  142. .queuecommand = ecoscsi_queue_command,
  143. .eh_abort_handler = NCR5380_abort,
  144. .eh_bus_reset_handler = NCR5380_bus_reset,
  145. .can_queue = 16,
  146. .this_id = 7,
  147. .sg_tablesize = SG_ALL,
  148. .cmd_per_lun = 2,
  149. .use_clustering = DISABLE_CLUSTERING
  150. };
  151. static struct Scsi_Host *host;
  152. static int __init ecoscsi_init(void)
  153. {
  154. host = scsi_host_alloc(tpnt, sizeof(struct NCR5380_hostdata));
  155. if (!host)
  156. return 0;
  157. host->io_port = 0x80ce8000;
  158. host->n_io_port = 144;
  159. host->irq = IRQ_NONE;
  160. if (!(request_region(host->io_port, host->n_io_port, "ecoscsi")) )
  161. goto unregister_scsi;
  162. ecoscsi_write(host, MODE_REG, 0x20); /* Is it really SCSI? */
  163. if (ecoscsi_read(host, MODE_REG) != 0x20) /* Write to a reg. */
  164. goto release_reg;
  165. ecoscsi_write(host, MODE_REG, 0x00 ); /* it back. */
  166. if (ecoscsi_read(host, MODE_REG) != 0x00)
  167. goto release_reg;
  168. NCR5380_init(host, 0);
  169. printk("scsi%d: at port 0x%08lx irqs disabled", host->host_no, host->io_port);
  170. printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
  171. host->can_queue, host->cmd_per_lun, ECOSCSI_PUBLIC_RELEASE);
  172. printk("\nscsi%d:", host->host_no);
  173. NCR5380_print_options(host);
  174. printk("\n");
  175. scsi_add_host(host, NULL); /* XXX handle failure */
  176. scsi_scan_host(host);
  177. return 0;
  178. release_reg:
  179. release_region(host->io_port, host->n_io_port);
  180. unregister_scsi:
  181. scsi_host_put(host);
  182. return -ENODEV;
  183. }
  184. static void __exit ecoscsi_exit(void)
  185. {
  186. scsi_remove_host(host);
  187. if (shpnt->irq != IRQ_NONE)
  188. free_irq(shpnt->irq, NULL);
  189. NCR5380_exit(host);
  190. if (shpnt->io_port)
  191. release_region(shpnt->io_port, shpnt->n_io_port);
  192. scsi_host_put(host);
  193. return 0;
  194. }
  195. module_init(ecoscsi_init);
  196. module_exit(ecoscsi_exit);
  197. MODULE_AUTHOR("Russell King");
  198. MODULE_DESCRIPTION("Econet-SCSI driver for Acorn machines");
  199. MODULE_LICENSE("GPL");