nsp_cs.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*=======================================================/
  2. Header file for nsp_cs.c
  3. By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
  4. Ver.1.0 : Cut unused lines.
  5. Ver 0.1 : Initial version.
  6. This software may be used and distributed according to the terms of
  7. the GNU General Public License.
  8. =========================================================*/
  9. #ifndef __nsp_cs__
  10. #define __nsp_cs__
  11. /* for debugging */
  12. //#define NSP_DEBUG 9
  13. /*
  14. #define static
  15. #define inline
  16. */
  17. /************************************
  18. * Some useful macros...
  19. */
  20. /* SCSI initiator must be ID 7 */
  21. #define NSP_INITIATOR_ID 7
  22. #define NSP_SELTIMEOUT 200
  23. /***************************************************************************
  24. * register definitions
  25. ***************************************************************************/
  26. /*========================================================================
  27. * base register
  28. ========================================================================*/
  29. #define IRQCONTROL 0x00 /* R */
  30. # define IRQCONTROL_RESELECT_CLEAR BIT(0)
  31. # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1)
  32. # define IRQCONTROL_TIMER_CLEAR BIT(2)
  33. # define IRQCONTROL_FIFO_CLEAR BIT(3)
  34. # define IRQCONTROL_ALLMASK 0xff
  35. # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \
  36. IRQCONTROL_PHASE_CHANGE_CLEAR | \
  37. IRQCONTROL_TIMER_CLEAR | \
  38. IRQCONTROL_FIFO_CLEAR )
  39. # define IRQCONTROL_IRQDISABLE 0xf0
  40. #define IRQSTATUS 0x00 /* W */
  41. # define IRQSTATUS_SCSI BIT(0)
  42. # define IRQSTATUS_TIMER BIT(2)
  43. # define IRQSTATUS_FIFO BIT(3)
  44. # define IRQSTATUS_MASK 0x0f
  45. #define IFSELECT 0x01 /* W */
  46. # define IF_IFSEL BIT(0)
  47. # define IF_REGSEL BIT(2)
  48. #define FIFOSTATUS 0x01 /* R */
  49. # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f
  50. # define FIFOSTATUS_CHIP_ID_MASK 0x70
  51. # define FIFOSTATUS_FULL_EMPTY BIT(7)
  52. #define INDEXREG 0x02 /* R/W */
  53. #define DATAREG 0x03 /* R/W */
  54. #define FIFODATA 0x04 /* R/W */
  55. #define FIFODATA1 0x05 /* R/W */
  56. #define FIFODATA2 0x06 /* R/W */
  57. #define FIFODATA3 0x07 /* R/W */
  58. /*====================================================================
  59. * indexed register
  60. ====================================================================*/
  61. #define EXTBUSCTRL 0x10 /* R/W,deleted */
  62. #define CLOCKDIV 0x11 /* R/W */
  63. # define CLOCK_40M 0x02
  64. # define CLOCK_20M 0x01
  65. # define FAST_20 BIT(2)
  66. #define TERMPWRCTRL 0x13 /* R/W */
  67. # define POWER_ON BIT(0)
  68. #define SCSIIRQMODE 0x15 /* R/W */
  69. # define SCSI_PHASE_CHANGE_EI BIT(0)
  70. # define RESELECT_EI BIT(4)
  71. # define FIFO_IRQ_EI BIT(5)
  72. # define SCSI_RESET_IRQ_EI BIT(6)
  73. #define IRQPHASESENCE 0x16 /* R */
  74. # define LATCHED_MSG BIT(0)
  75. # define LATCHED_IO BIT(1)
  76. # define LATCHED_CD BIT(2)
  77. # define LATCHED_BUS_FREE BIT(3)
  78. # define PHASE_CHANGE_IRQ BIT(4)
  79. # define RESELECT_IRQ BIT(5)
  80. # define FIFO_IRQ BIT(6)
  81. # define SCSI_RESET_IRQ BIT(7)
  82. #define TIMERCOUNT 0x17 /* R/W */
  83. #define SCSIBUSCTRL 0x18 /* R/W */
  84. # define SCSI_SEL BIT(0)
  85. # define SCSI_RST BIT(1)
  86. # define SCSI_DATAOUT_ENB BIT(2)
  87. # define SCSI_ATN BIT(3)
  88. # define SCSI_ACK BIT(4)
  89. # define SCSI_BSY BIT(5)
  90. # define AUTODIRECTION BIT(6)
  91. # define ACKENB BIT(7)
  92. #define SCSIBUSMON 0x19 /* R */
  93. #define SETARBIT 0x1A /* W */
  94. # define ARBIT_GO BIT(0)
  95. # define ARBIT_FLAG_CLEAR BIT(1)
  96. #define ARBITSTATUS 0x1A /* R */
  97. /*# define ARBIT_GO BIT(0)*/
  98. # define ARBIT_WIN BIT(1)
  99. # define ARBIT_FAIL BIT(2)
  100. # define RESELECT_FLAG BIT(3)
  101. #define PARITYCTRL 0x1B /* W */
  102. #define PARITYSTATUS 0x1B /* R */
  103. #define COMMANDCTRL 0x1C /* W */
  104. # define CLEAR_COMMAND_POINTER BIT(0)
  105. # define AUTO_COMMAND_GO BIT(1)
  106. #define RESELECTID 0x1C /* R */
  107. #define COMMANDDATA 0x1D /* R/W */
  108. #define POINTERCLR 0x1E /* W */
  109. # define POINTER_CLEAR BIT(0)
  110. # define ACK_COUNTER_CLEAR BIT(1)
  111. # define REQ_COUNTER_CLEAR BIT(2)
  112. # define HOST_COUNTER_CLEAR BIT(3)
  113. # define READ_SOURCE (BIT(4) | BIT(5))
  114. # define ACK_COUNTER (0)
  115. # define REQ_COUNTER (BIT(4))
  116. # define HOST_COUNTER (BIT(5))
  117. #define TRANSFERCOUNT 0x1E /* R */
  118. #define TRANSFERMODE 0x20 /* R/W */
  119. # define MODE_MEM8 BIT(0)
  120. # define MODE_MEM32 BIT(1)
  121. # define MODE_ADR24 BIT(2)
  122. # define MODE_ADR32 BIT(3)
  123. # define MODE_IO8 BIT(4)
  124. # define MODE_IO32 BIT(5)
  125. # define TRANSFER_GO BIT(6)
  126. # define BRAIND BIT(7)
  127. #define SYNCREG 0x21 /* R/W */
  128. # define SYNCREG_OFFSET_MASK 0x0f
  129. # define SYNCREG_PERIOD_MASK 0xf0
  130. # define SYNCREG_PERIOD_SHIFT 4
  131. #define SCSIDATALATCH 0x22 /* W */
  132. #define SCSIDATAIN 0x22 /* R */
  133. #define SCSIDATAWITHACK 0x23 /* R/W */
  134. #define SCAMCONTROL 0x24 /* W */
  135. #define SCAMSTATUS 0x24 /* R */
  136. #define SCAMDATA 0x25 /* R/W */
  137. #define OTHERCONTROL 0x26 /* R/W */
  138. # define TPL_ROM_WRITE_EN BIT(0)
  139. # define TPWR_OUT BIT(1)
  140. # define TPWR_SENSE BIT(2)
  141. # define RA8_CONTROL BIT(3)
  142. #define ACKWIDTH 0x27 /* R/W */
  143. #define CLRTESTPNT 0x28 /* W */
  144. #define ACKCNTLD 0x29 /* W */
  145. #define REQCNTLD 0x2A /* W */
  146. #define HSTCNTLD 0x2B /* W */
  147. #define CHECKSUM 0x2C /* R/W */
  148. /************************************************************************
  149. * Input status bit definitions.
  150. ************************************************************************/
  151. #define S_MESSAGE BIT(0) /* Message line from SCSI bus */
  152. #define S_IO BIT(1) /* Input/Output line from SCSI bus */
  153. #define S_CD BIT(2) /* Command/Data line from SCSI bus */
  154. #define S_BUSY BIT(3) /* Busy line from SCSI bus */
  155. #define S_ACK BIT(4) /* Acknowledge line from SCSI bus */
  156. #define S_REQUEST BIT(5) /* Request line from SCSI bus */
  157. #define S_SELECT BIT(6) /* */
  158. #define S_ATN BIT(7) /* */
  159. /***********************************************************************
  160. * Useful Bus Monitor status combinations.
  161. ***********************************************************************/
  162. #define BUSMON_SEL S_SELECT
  163. #define BUSMON_BSY S_BUSY
  164. #define BUSMON_REQ S_REQUEST
  165. #define BUSMON_IO S_IO
  166. #define BUSMON_ACK S_ACK
  167. #define BUSMON_BUS_FREE 0
  168. #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST )
  169. #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST )
  170. #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST )
  171. #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST )
  172. #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST )
  173. #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST )
  174. #define BUSMON_SELECT ( S_IO | S_SELECT )
  175. #define BUSMON_RESELECT ( S_IO | S_SELECT )
  176. #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT )
  177. #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK )
  178. #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK )
  179. #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK )
  180. #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK )
  181. #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK )
  182. #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK )
  183. #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK )
  184. /*====================================================================*/
  185. typedef struct scsi_info_t {
  186. struct pcmcia_device *p_dev;
  187. struct Scsi_Host *host;
  188. int stop;
  189. } scsi_info_t;
  190. /* synchronous transfer negotiation data */
  191. typedef struct _sync_data {
  192. unsigned int SyncNegotiation;
  193. #define SYNC_NOT_YET 0
  194. #define SYNC_OK 1
  195. #define SYNC_NG 2
  196. unsigned int SyncPeriod;
  197. unsigned int SyncOffset;
  198. unsigned char SyncRegister;
  199. unsigned char AckWidth;
  200. } sync_data;
  201. typedef struct _nsp_hw_data {
  202. unsigned int BaseAddress;
  203. unsigned int NumAddress;
  204. unsigned int IrqNumber;
  205. unsigned long MmioAddress;
  206. #define NSP_MMIO_OFFSET 0x0800
  207. unsigned long MmioLength;
  208. unsigned char ScsiClockDiv;
  209. unsigned char TransferMode;
  210. int TimerCount;
  211. int SelectionTimeOut;
  212. struct scsi_cmnd *CurrentSC;
  213. //int CurrnetTarget;
  214. int FifoCount;
  215. #define MSGBUF_SIZE 20
  216. unsigned char MsgBuffer[MSGBUF_SIZE];
  217. int MsgLen;
  218. #define N_TARGET 8
  219. sync_data Sync[N_TARGET];
  220. char nspinfo[110]; /* description */
  221. spinlock_t Lock;
  222. scsi_info_t *ScsiInfo; /* attach <-> detect glue */
  223. #ifdef NSP_DEBUG
  224. int CmdId; /* Accepted command serial number.
  225. Used for debugging. */
  226. #endif
  227. } nsp_hw_data;
  228. /****************************************************************************
  229. *
  230. */
  231. /* Card service functions */
  232. static void nsp_cs_detach (struct pcmcia_device *p_dev);
  233. static void nsp_cs_release(struct pcmcia_device *link);
  234. static int nsp_cs_config (struct pcmcia_device *link);
  235. /* Linux SCSI subsystem specific functions */
  236. static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
  237. static const char *nsp_info (struct Scsi_Host *shpnt);
  238. static int nsp_show_info (struct seq_file *m,
  239. struct Scsi_Host *host);
  240. static int nsp_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *SCpnt);
  241. /* Error handler */
  242. /*static int nsp_eh_abort (struct scsi_cmnd *SCpnt);*/
  243. /*static int nsp_eh_device_reset(struct scsi_cmnd *SCpnt);*/
  244. static int nsp_eh_bus_reset (struct scsi_cmnd *SCpnt);
  245. static int nsp_eh_host_reset (struct scsi_cmnd *SCpnt);
  246. static int nsp_bus_reset (nsp_hw_data *data);
  247. /* */
  248. static int nsphw_init (nsp_hw_data *data);
  249. static int nsphw_start_selection(struct scsi_cmnd *SCpnt);
  250. static void nsp_start_timer (struct scsi_cmnd *SCpnt, int time);
  251. static int nsp_fifo_count (struct scsi_cmnd *SCpnt);
  252. static void nsp_pio_read (struct scsi_cmnd *SCpnt);
  253. static void nsp_pio_write (struct scsi_cmnd *SCpnt);
  254. static int nsp_nexus (struct scsi_cmnd *SCpnt);
  255. static void nsp_scsi_done (struct scsi_cmnd *SCpnt);
  256. static int nsp_analyze_sdtr (struct scsi_cmnd *SCpnt);
  257. static int nsp_negate_signal (struct scsi_cmnd *SCpnt,
  258. unsigned char mask, char *str);
  259. static int nsp_expect_signal (struct scsi_cmnd *SCpnt,
  260. unsigned char current_phase,
  261. unsigned char mask);
  262. static int nsp_xfer (struct scsi_cmnd *SCpnt, int phase);
  263. static int nsp_dataphase_bypass (struct scsi_cmnd *SCpnt);
  264. static int nsp_reselected (struct scsi_cmnd *SCpnt);
  265. static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht);
  266. /* Interrupt handler */
  267. //static irqreturn_t nspintr(int irq, void *dev_id);
  268. /* Module entry point*/
  269. static int __init nsp_cs_init(void);
  270. static void __exit nsp_cs_exit(void);
  271. /* Debug */
  272. #ifdef NSP_DEBUG
  273. static void show_command (struct scsi_cmnd *SCpnt);
  274. static void show_phase (struct scsi_cmnd *SCpnt);
  275. static void show_busphase(unsigned char stat);
  276. static void show_message (nsp_hw_data *data);
  277. #else
  278. # define show_command(ptr) /* */
  279. # define show_phase(SCpnt) /* */
  280. # define show_busphase(stat) /* */
  281. # define show_message(data) /* */
  282. #endif
  283. /*
  284. * SCSI phase
  285. */
  286. enum _scsi_phase {
  287. PH_UNDETERMINED ,
  288. PH_ARBSTART ,
  289. PH_SELSTART ,
  290. PH_SELECTED ,
  291. PH_COMMAND ,
  292. PH_DATA ,
  293. PH_STATUS ,
  294. PH_MSG_IN ,
  295. PH_MSG_OUT ,
  296. PH_DISCONNECT ,
  297. PH_RESELECT ,
  298. PH_ABORT ,
  299. PH_RESET
  300. };
  301. enum _data_in_out {
  302. IO_UNKNOWN,
  303. IO_IN,
  304. IO_OUT
  305. };
  306. enum _burst_mode {
  307. BURST_IO8 = 0,
  308. BURST_IO32 = 1,
  309. BURST_MEM32 = 2,
  310. };
  311. /**************************************************************************
  312. * SCSI messaage
  313. */
  314. #define MSG_COMMAND_COMPLETE 0x00
  315. #define MSG_EXTENDED 0x01
  316. #define MSG_ABORT 0x06
  317. #define MSG_NO_OPERATION 0x08
  318. #define MSG_BUS_DEVICE_RESET 0x0c
  319. #define MSG_EXT_SDTR 0x01
  320. /* scatter-gather table */
  321. # define BUFFER_ADDR ((char *)((sg_virt(SCpnt->SCp.buffer))))
  322. #endif /*__nsp_cs__*/
  323. /* end */