fas216.h 14 KB

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