fas216.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * linux/drivers/acorn/scsi/fas216.h
  3. *
  4. * Copyright (C) 1997-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * FAS216 generic driver
  11. */
  12. #ifndef FAS216_H
  13. #define FAS216_H
  14. #ifndef NO_IRQ
  15. #define NO_IRQ 255
  16. #endif
  17. #include "queue.h"
  18. #include "msgqueue.h"
  19. /* FAS register definitions */
  20. /* transfer count low */
  21. #define REG_CTCL (0)
  22. #define REG_STCL (0)
  23. /* transfer count medium */
  24. #define REG_CTCM (1)
  25. #define REG_STCM (1)
  26. /* fifo data */
  27. #define REG_FF (2)
  28. /* command */
  29. #define REG_CMD (3)
  30. #define CMD_NOP 0x00
  31. #define CMD_FLUSHFIFO 0x01
  32. #define CMD_RESETCHIP 0x02
  33. #define CMD_RESETSCSI 0x03
  34. #define CMD_TRANSFERINFO 0x10
  35. #define CMD_INITCMDCOMPLETE 0x11
  36. #define CMD_MSGACCEPTED 0x12
  37. #define CMD_PADBYTES 0x18
  38. #define CMD_SETATN 0x1a
  39. #define CMD_RSETATN 0x1b
  40. #define CMD_SELECTWOATN 0x41
  41. #define CMD_SELECTATN 0x42
  42. #define CMD_SELECTATNSTOP 0x43
  43. #define CMD_ENABLESEL 0x44
  44. #define CMD_DISABLESEL 0x45
  45. #define CMD_SELECTATN3 0x46
  46. #define CMD_RESEL3 0x47
  47. #define CMD_WITHDMA 0x80
  48. /* status register (read) */
  49. #define REG_STAT (4)
  50. #define STAT_IO (1 << 0) /* IO phase */
  51. #define STAT_CD (1 << 1) /* CD phase */
  52. #define STAT_MSG (1 << 2) /* MSG phase */
  53. #define STAT_TRANSFERDONE (1 << 3) /* Transfer completed */
  54. #define STAT_TRANSFERCNTZ (1 << 4) /* Transfer counter is zero */
  55. #define STAT_PARITYERROR (1 << 5) /* Parity error */
  56. #define STAT_REALBAD (1 << 6) /* Something bad */
  57. #define STAT_INT (1 << 7) /* Interrupt */
  58. #define STAT_BUSMASK (STAT_MSG|STAT_CD|STAT_IO)
  59. #define STAT_DATAOUT (0) /* Data out */
  60. #define STAT_DATAIN (STAT_IO) /* Data in */
  61. #define STAT_COMMAND (STAT_CD) /* Command out */
  62. #define STAT_STATUS (STAT_CD|STAT_IO) /* Status In */
  63. #define STAT_MESGOUT (STAT_MSG|STAT_CD) /* Message out */
  64. #define STAT_MESGIN (STAT_MSG|STAT_CD|STAT_IO) /* Message In */
  65. /* bus ID for select / reselect */
  66. #define REG_SDID (4)
  67. #define BUSID(target) ((target) & 7)
  68. /* Interrupt status register (read) */
  69. #define REG_INST (5)
  70. #define INST_SELWOATN (1 << 0) /* Select w/o ATN */
  71. #define INST_SELATN (1 << 1) /* Select w/ATN */
  72. #define INST_RESELECTED (1 << 2) /* Reselected */
  73. #define INST_FUNCDONE (1 << 3) /* Function done */
  74. #define INST_BUSSERVICE (1 << 4) /* Bus service */
  75. #define INST_DISCONNECT (1 << 5) /* Disconnect */
  76. #define INST_ILLEGALCMD (1 << 6) /* Illegal command */
  77. #define INST_BUSRESET (1 << 7) /* SCSI Bus reset */
  78. /* Timeout register (write) */
  79. #define REG_STIM (5)
  80. /* Sequence step register (read) */
  81. #define REG_IS (6)
  82. #define IS_BITS 0x07
  83. #define IS_SELARB 0x00 /* Select & Arb ok */
  84. #define IS_MSGBYTESENT 0x01 /* One byte message sent*/
  85. #define IS_NOTCOMMAND 0x02 /* Not in command state */
  86. #define IS_EARLYPHASE 0x03 /* Early phase change */
  87. #define IS_COMPLETE 0x04 /* Command ok */
  88. #define IS_SOF 0x08 /* Sync off flag */
  89. /* Transfer period step (write) */
  90. #define REG_STP (6)
  91. /* Synchronous Offset (write) */
  92. #define REG_SOF (7)
  93. /* Fifo state register (read) */
  94. #define REG_CFIS (7)
  95. #define CFIS_CF 0x1f /* Num bytes in FIFO */
  96. #define CFIS_IS 0xe0 /* Step */
  97. /* config register 1 */
  98. #define REG_CNTL1 (8)
  99. #define CNTL1_CID (7 << 0) /* Chip ID */
  100. #define CNTL1_STE (1 << 3) /* Self test enable */
  101. #define CNTL1_PERE (1 << 4) /* Parity enable reporting en. */
  102. #define CNTL1_PTE (1 << 5) /* Parity test enable */
  103. #define CNTL1_DISR (1 << 6) /* Disable Irq on SCSI reset */
  104. #define CNTL1_ETM (1 << 7) /* Extended Timing Mode */
  105. /* Clock conversion factor (read) */
  106. #define REG_CLKF (9)
  107. #define CLKF_F37MHZ 0x00 /* 35.01 - 40 MHz */
  108. #define CLKF_F10MHZ 0x02 /* 10 MHz */
  109. #define CLKF_F12MHZ 0x03 /* 10.01 - 15 MHz */
  110. #define CLKF_F17MHZ 0x04 /* 15.01 - 20 MHz */
  111. #define CLKF_F22MHZ 0x05 /* 20.01 - 25 MHz */
  112. #define CLKF_F27MHZ 0x06 /* 25.01 - 30 MHz */
  113. #define CLKF_F32MHZ 0x07 /* 30.01 - 35 MHz */
  114. /* Chip test register (write) */
  115. #define REG_FTM (10)
  116. #define TEST_FTM 0x01 /* Force target mode */
  117. #define TEST_FIM 0x02 /* Force initiator mode */
  118. #define TEST_FHI 0x04 /* Force high impedance mode */
  119. /* Configuration register 2 (read/write) */
  120. #define REG_CNTL2 (11)
  121. #define CNTL2_PGDP (1 << 0) /* Pass Th/Generate Data Parity */
  122. #define CNTL2_PGRP (1 << 1) /* Pass Th/Generate Reg Parity */
  123. #define CNTL2_ACDPE (1 << 2) /* Abort on Cmd/Data Parity Err */
  124. #define CNTL2_S2FE (1 << 3) /* SCSI2 Features Enable */
  125. #define CNTL2_TSDR (1 << 4) /* Tristate DREQ */
  126. #define CNTL2_SBO (1 << 5) /* Select Byte Order */
  127. #define CNTL2_ENF (1 << 6) /* Enable features */
  128. #define CNTL2_DAE (1 << 7) /* Data Alignment Enable */
  129. /* Configuration register 3 (read/write) */
  130. #define REG_CNTL3 (12)
  131. #define CNTL3_BS8 (1 << 0) /* Burst size 8 */
  132. #define CNTL3_MDM (1 << 1) /* Modify DMA mode */
  133. #define CNTL3_LBTM (1 << 2) /* Last Byte Transfer mode */
  134. #define CNTL3_FASTCLK (1 << 3) /* Fast SCSI clocking */
  135. #define CNTL3_FASTSCSI (1 << 4) /* Fast SCSI */
  136. #define CNTL3_G2CB (1 << 5) /* Group2 SCSI support */
  137. #define CNTL3_QTAG (1 << 6) /* Enable 3 byte msgs */
  138. #define CNTL3_ADIDCHK (1 << 7) /* Additional ID check */
  139. /* High transfer count (read/write) */
  140. #define REG_CTCH (14)
  141. #define REG_STCH (14)
  142. /* ID register (read only) */
  143. #define REG_ID (14)
  144. /* Data alignment */
  145. #define REG_DAL (15)
  146. typedef enum {
  147. PHASE_IDLE, /* we're not planning on doing anything */
  148. PHASE_SELECTION, /* selecting a device */
  149. PHASE_SELSTEPS, /* selection with command steps */
  150. PHASE_COMMAND, /* command sent */
  151. PHASE_MESSAGESENT, /* selected, and we're sending cmd */
  152. PHASE_DATAOUT, /* data out to device */
  153. PHASE_DATAIN, /* data in from device */
  154. PHASE_MSGIN, /* message in from device */
  155. PHASE_MSGIN_DISCONNECT, /* disconnecting from bus */
  156. PHASE_MSGOUT, /* after message out phase */
  157. PHASE_MSGOUT_EXPECT, /* expecting message out */
  158. PHASE_STATUS, /* status from device */
  159. PHASE_DONE /* Command complete */
  160. } phase_t;
  161. typedef enum {
  162. DMA_OUT, /* DMA from memory to chip */
  163. DMA_IN /* DMA from chip to memory */
  164. } fasdmadir_t;
  165. typedef enum {
  166. fasdma_none, /* No dma */
  167. fasdma_pio, /* PIO mode */
  168. fasdma_pseudo, /* Pseudo DMA */
  169. fasdma_real_block, /* Real DMA, on block by block basis */
  170. fasdma_real_all /* Real DMA, on request by request */
  171. } fasdmatype_t;
  172. typedef enum {
  173. neg_wait, /* Negociate with device */
  174. neg_inprogress, /* Negociation sent */
  175. neg_complete, /* Negociation complete */
  176. neg_targcomplete, /* Target completed negociation */
  177. neg_invalid /* Negociation not supported */
  178. } neg_t;
  179. #define MAGIC 0x441296bdUL
  180. #define NR_MSGS 8
  181. #define FASCAP_DMA (1 << 0)
  182. #define FASCAP_PSEUDODMA (1 << 1)
  183. typedef struct {
  184. unsigned long magic_start;
  185. spinlock_t host_lock;
  186. struct Scsi_Host *host; /* host */
  187. Scsi_Cmnd *SCpnt; /* currently processing command */
  188. Scsi_Cmnd *origSCpnt; /* original connecting command */
  189. Scsi_Cmnd *reqSCpnt; /* request sense command */
  190. Scsi_Cmnd *rstSCpnt; /* reset command */
  191. Scsi_Cmnd *pending_SCpnt[8]; /* per-device pending commands */
  192. int next_pending; /* next pending device */
  193. /*
  194. * Error recovery
  195. */
  196. wait_queue_head_t eh_wait;
  197. struct timer_list eh_timer;
  198. unsigned int rst_dev_status;
  199. unsigned int rst_bus_status;
  200. /* driver information */
  201. struct {
  202. phase_t phase; /* current phase */
  203. void __iomem *io_base; /* iomem base of FAS216 */
  204. unsigned int io_shift; /* shift to adjust reg offsets by */
  205. unsigned char cfg[4]; /* configuration registers */
  206. const char *type; /* chip type */
  207. unsigned int irq; /* interrupt */
  208. int dma; /* dma channel */
  209. struct scsi_pointer SCp; /* current commands data pointer */
  210. MsgQueue_t msgs; /* message queue for connected device */
  211. unsigned int async_stp; /* Async transfer STP value */
  212. unsigned char msgin_fifo; /* bytes in fifo at time of message in */
  213. unsigned char message[256]; /* last message received from device */
  214. unsigned char disconnectable:1; /* this command can be disconnected */
  215. unsigned char aborting:1; /* aborting command */
  216. } scsi;
  217. /* statistics information */
  218. struct {
  219. unsigned int queues;
  220. unsigned int removes;
  221. unsigned int fins;
  222. unsigned int reads;
  223. unsigned int writes;
  224. unsigned int miscs;
  225. unsigned int disconnects;
  226. unsigned int aborts;
  227. unsigned int bus_resets;
  228. unsigned int host_resets;
  229. } stats;
  230. /* configuration information */
  231. struct {
  232. unsigned char clockrate; /* clock rate of FAS device (MHz) */
  233. unsigned char select_timeout; /* timeout (R5) */
  234. unsigned char sync_max_depth; /* Synchronous xfer max fifo depth */
  235. unsigned char wide_max_size; /* Maximum wide transfer size */
  236. unsigned char cntl3; /* Control Reg 3 */
  237. unsigned int asyncperiod; /* Async transfer period (ns) */
  238. unsigned int capabilities; /* driver capabilities */
  239. unsigned int disconnect_ok:1; /* Disconnects allowed? */
  240. } ifcfg;
  241. /* queue handling */
  242. struct {
  243. Queue_t issue; /* issue queue */
  244. Queue_t disconnected; /* disconnected command queue */
  245. } queues;
  246. /* per-device info */
  247. struct fas216_device {
  248. unsigned char disconnect_ok:1; /* device can disconnect */
  249. unsigned char parity_enabled:1; /* parity checking enabled */
  250. unsigned char parity_check:1; /* need to check parity checking */
  251. unsigned char period; /* sync xfer period in (*4ns) */
  252. unsigned char stp; /* synchronous transfer period */
  253. unsigned char sof; /* synchronous offset register */
  254. unsigned char wide_xfer; /* currently negociated wide transfer */
  255. neg_t sync_state; /* synchronous transfer mode */
  256. neg_t wide_state; /* wide transfer mode */
  257. } device[8];
  258. unsigned long busyluns[64/sizeof(unsigned long)];/* array of bits indicating LUNs busy */
  259. /* dma */
  260. struct {
  261. fasdmatype_t transfer_type; /* current type of DMA transfer */
  262. fasdmatype_t (*setup) (struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, fasdmatype_t min_dma);
  263. void (*pseudo)(struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, int transfer);
  264. void (*stop) (struct Scsi_Host *host, struct scsi_pointer *SCp);
  265. } dma;
  266. /* miscellaneous */
  267. int internal_done; /* flag to indicate request done */
  268. unsigned long magic_end;
  269. } FAS216_Info;
  270. /* Function: int fas216_init (struct Scsi_Host *instance)
  271. * Purpose : initialise FAS/NCR/AMD SCSI structures.
  272. * Params : instance - a driver-specific filled-out structure
  273. * Returns : 0 on success
  274. */
  275. extern int fas216_init (struct Scsi_Host *instance);
  276. /* Function: int fas216_add (struct Scsi_Host *instance, struct device *dev)
  277. * Purpose : initialise FAS/NCR/AMD SCSI ic.
  278. * Params : instance - a driver-specific filled-out structure
  279. * Returns : 0 on success
  280. */
  281. extern int fas216_add (struct Scsi_Host *instance, struct device *dev);
  282. /* Function: int fas216_queue_command (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
  283. * Purpose : queue a command for adapter to process.
  284. * Params : SCpnt - Command to queue
  285. * done - done function to call once command is complete
  286. * Returns : 0 - success, else error
  287. */
  288. extern int fas216_queue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
  289. /* Function: int fas216_noqueue_command (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
  290. * Purpose : queue a command for adapter to process, and process it to completion.
  291. * Params : SCpnt - Command to queue
  292. * done - done function to call once command is complete
  293. * Returns : 0 - success, else error
  294. */
  295. extern int fas216_noqueue_command (Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
  296. /* Function: irqreturn_t fas216_intr (FAS216_Info *info)
  297. * Purpose : handle interrupts from the interface to progress a command
  298. * Params : info - interface to service
  299. */
  300. extern irqreturn_t fas216_intr (FAS216_Info *info);
  301. extern void fas216_remove (struct Scsi_Host *instance);
  302. /* Function: void fas216_release (struct Scsi_Host *instance)
  303. * Purpose : release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
  304. * Params : instance - a driver-specific filled-out structure
  305. * Returns : 0 on success
  306. */
  307. extern void fas216_release (struct Scsi_Host *instance);
  308. extern int fas216_print_host(FAS216_Info *info, char *buffer);
  309. extern int fas216_print_stats(FAS216_Info *info, char *buffer);
  310. extern int fas216_print_devices(FAS216_Info *info, char *buffer);
  311. /* Function: int fas216_eh_abort(Scsi_Cmnd *SCpnt)
  312. * Purpose : abort this command
  313. * Params : SCpnt - command to abort
  314. * Returns : FAILED if unable to abort
  315. */
  316. extern int fas216_eh_abort(Scsi_Cmnd *SCpnt);
  317. /* Function: int fas216_eh_device_reset(Scsi_Cmnd *SCpnt)
  318. * Purpose : Reset the device associated with this command
  319. * Params : SCpnt - command specifing device to reset
  320. * Returns : FAILED if unable to reset
  321. */
  322. extern int fas216_eh_device_reset(Scsi_Cmnd *SCpnt);
  323. /* Function: int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt)
  324. * Purpose : Reset the complete bus associated with this command
  325. * Params : SCpnt - command specifing bus to reset
  326. * Returns : FAILED if unable to reset
  327. */
  328. extern int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt);
  329. /* Function: int fas216_eh_host_reset(Scsi_Cmnd *SCpnt)
  330. * Purpose : Reset the host associated with this command
  331. * Params : SCpnt - command specifing host to reset
  332. * Returns : FAILED if unable to reset
  333. */
  334. extern int fas216_eh_host_reset(Scsi_Cmnd *SCpnt);
  335. #endif /* FAS216_H */