oak.c 4.6 KB

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