ecoscsi.c 5.1 KB

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