53c700.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /* Driver for 53c700 and 53c700-66 chips from NCR and Symbios
  3. *
  4. * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
  5. */
  6. #ifndef _53C700_H
  7. #define _53C700_H
  8. #include <linux/interrupt.h>
  9. #include <asm/io.h>
  10. #include <scsi/scsi_device.h>
  11. /* Turn on for general debugging---too verbose for normal use */
  12. #undef NCR_700_DEBUG
  13. /* Debug the tag queues, checking hash queue allocation and deallocation
  14. * and search for duplicate tags */
  15. #undef NCR_700_TAG_DEBUG
  16. #ifdef NCR_700_DEBUG
  17. #define DEBUG(x) printk x
  18. #define DDEBUG(prefix, sdev, fmt, a...) \
  19. sdev_printk(prefix, sdev, fmt, ##a)
  20. #define CDEBUG(prefix, scmd, fmt, a...) \
  21. scmd_printk(prefix, scmd, fmt, ##a)
  22. #else
  23. #define DEBUG(x) do {} while (0)
  24. #define DDEBUG(prefix, scmd, fmt, a...) do {} while (0)
  25. #define CDEBUG(prefix, scmd, fmt, a...) do {} while (0)
  26. #endif
  27. /* The number of available command slots */
  28. #define NCR_700_COMMAND_SLOTS_PER_HOST 64
  29. /* The maximum number of Scatter Gathers we allow */
  30. #define NCR_700_SG_SEGMENTS 32
  31. /* The maximum number of luns (make this of the form 2^n) */
  32. #define NCR_700_MAX_LUNS 32
  33. #define NCR_700_LUN_MASK (NCR_700_MAX_LUNS - 1)
  34. /* Maximum number of tags the driver ever allows per device */
  35. #define NCR_700_MAX_TAGS 16
  36. /* Tag depth the driver starts out with (can be altered in sysfs) */
  37. #define NCR_700_DEFAULT_TAGS 4
  38. /* This is the default number of commands per LUN in the untagged case.
  39. * two is a good value because it means we can have one command active and
  40. * one command fully prepared and waiting
  41. */
  42. #define NCR_700_CMD_PER_LUN 2
  43. /* magic byte identifying an internally generated REQUEST_SENSE command */
  44. #define NCR_700_INTERNAL_SENSE_MAGIC 0x42
  45. struct NCR_700_Host_Parameters;
  46. /* These are the externally used routines */
  47. struct Scsi_Host *NCR_700_detect(struct scsi_host_template *,
  48. struct NCR_700_Host_Parameters *, struct device *);
  49. int NCR_700_release(struct Scsi_Host *host);
  50. irqreturn_t NCR_700_intr(int, void *, struct pt_regs *);
  51. enum NCR_700_Host_State {
  52. NCR_700_HOST_BUSY,
  53. NCR_700_HOST_FREE,
  54. };
  55. struct NCR_700_SG_List {
  56. /* The following is a script fragment to move the buffer onto the
  57. * bus and then link the next fragment or return */
  58. #define SCRIPT_MOVE_DATA_IN 0x09000000
  59. #define SCRIPT_MOVE_DATA_OUT 0x08000000
  60. __u32 ins;
  61. __u32 pAddr;
  62. #define SCRIPT_NOP 0x80000000
  63. #define SCRIPT_RETURN 0x90080000
  64. };
  65. /* We use device->hostdata to store negotiated parameters. This is
  66. * supposed to be a pointer to a device private area, but we cannot
  67. * really use it as such since it will never be freed, so just use the
  68. * 32 bits to cram the information. The SYNC negotiation sequence looks
  69. * like:
  70. *
  71. * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the
  72. * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTATION
  73. * If we get an SDTR reply, work out the SXFER parameters, squirrel
  74. * them away here, clear DEV_BEGIN_SYNC_NEGOTIATION and set
  75. * DEV_NEGOTIATED_SYNC. If we get a REJECT msg, squirrel
  76. *
  77. *
  78. * 0:7 SXFER_REG negotiated value for this device
  79. * 8:15 Current queue depth
  80. * 16 negotiated SYNC flag
  81. * 17 begin SYNC negotiation flag
  82. * 18 device supports tag queueing */
  83. #define NCR_700_DEV_NEGOTIATED_SYNC (1<<16)
  84. #define NCR_700_DEV_BEGIN_SYNC_NEGOTIATION (1<<17)
  85. #define NCR_700_DEV_PRINT_SYNC_NEGOTIATION (1<<19)
  86. static inline void
  87. NCR_700_set_depth(struct scsi_device *SDp, __u8 depth)
  88. {
  89. long l = (long)SDp->hostdata;
  90. l &= 0xffff00ff;
  91. l |= 0xff00 & (depth << 8);
  92. SDp->hostdata = (void *)l;
  93. }
  94. static inline __u8
  95. NCR_700_get_depth(struct scsi_device *SDp)
  96. {
  97. return ((((unsigned long)SDp->hostdata) & 0xff00)>>8);
  98. }
  99. static inline int
  100. NCR_700_is_flag_set(struct scsi_device *SDp, __u32 flag)
  101. {
  102. return (spi_flags(SDp->sdev_target) & flag) == flag;
  103. }
  104. static inline int
  105. NCR_700_is_flag_clear(struct scsi_device *SDp, __u32 flag)
  106. {
  107. return (spi_flags(SDp->sdev_target) & flag) == 0;
  108. }
  109. static inline void
  110. NCR_700_set_flag(struct scsi_device *SDp, __u32 flag)
  111. {
  112. spi_flags(SDp->sdev_target) |= flag;
  113. }
  114. static inline void
  115. NCR_700_clear_flag(struct scsi_device *SDp, __u32 flag)
  116. {
  117. spi_flags(SDp->sdev_target) &= ~flag;
  118. }
  119. enum NCR_700_tag_neg_state {
  120. NCR_700_START_TAG_NEGOTIATION = 0,
  121. NCR_700_DURING_TAG_NEGOTIATION = 1,
  122. NCR_700_FINISHED_TAG_NEGOTIATION = 2,
  123. };
  124. static inline enum NCR_700_tag_neg_state
  125. NCR_700_get_tag_neg_state(struct scsi_device *SDp)
  126. {
  127. return (enum NCR_700_tag_neg_state)((spi_flags(SDp->sdev_target)>>20) & 0x3);
  128. }
  129. static inline void
  130. NCR_700_set_tag_neg_state(struct scsi_device *SDp,
  131. enum NCR_700_tag_neg_state state)
  132. {
  133. /* clear the slot */
  134. spi_flags(SDp->sdev_target) &= ~(0x3 << 20);
  135. spi_flags(SDp->sdev_target) |= ((__u32)state) << 20;
  136. }
  137. struct NCR_700_command_slot {
  138. struct NCR_700_SG_List SG[NCR_700_SG_SEGMENTS+1];
  139. struct NCR_700_SG_List *pSG;
  140. #define NCR_700_SLOT_MASK 0xFC
  141. #define NCR_700_SLOT_MAGIC 0xb8
  142. #define NCR_700_SLOT_FREE (0|NCR_700_SLOT_MAGIC) /* slot may be used */
  143. #define NCR_700_SLOT_BUSY (1|NCR_700_SLOT_MAGIC) /* slot has command active on HA */
  144. #define NCR_700_SLOT_QUEUED (2|NCR_700_SLOT_MAGIC) /* slot has command to be made active on HA */
  145. __u8 state;
  146. #define NCR_700_FLAG_AUTOSENSE 0x01
  147. __u8 flags;
  148. int tag;
  149. __u32 resume_offset;
  150. struct scsi_cmnd *cmnd;
  151. /* The pci_mapped address of the actual command in cmnd */
  152. dma_addr_t pCmd;
  153. __u32 temp;
  154. /* if this command is a pci_single mapping, holds the dma address
  155. * for later unmapping in the done routine */
  156. dma_addr_t dma_handle;
  157. /* historical remnant, now used to link free commands */
  158. struct NCR_700_command_slot *ITL_forw;
  159. };
  160. struct NCR_700_Host_Parameters {
  161. /* These must be filled in by the calling driver */
  162. int clock; /* board clock speed in MHz */
  163. void __iomem *base; /* the base for the port (copied to host) */
  164. struct device *dev;
  165. __u32 dmode_extra; /* adjustable bus settings */
  166. __u32 differential:1; /* if we are differential */
  167. #ifdef CONFIG_53C700_LE_ON_BE
  168. /* This option is for HP only. Set it if your chip is wired for
  169. * little endian on this platform (which is big endian) */
  170. __u32 force_le_on_be:1;
  171. #endif
  172. __u32 chip710:1; /* set if really a 710 not 700 */
  173. __u32 burst_disable:1; /* set to 1 to disable 710 bursting */
  174. /* NOTHING BELOW HERE NEEDS ALTERING */
  175. __u32 fast:1; /* if we can alter the SCSI bus clock
  176. speed (so can negiotiate sync) */
  177. int sync_clock; /* The speed of the SYNC core */
  178. __u32 *script; /* pointer to script location */
  179. __u32 pScript; /* physical mem addr of script */
  180. enum NCR_700_Host_State state; /* protected by state lock */
  181. struct scsi_cmnd *cmd;
  182. /* Note: pScript contains the single consistent block of
  183. * memory. All the msgin, msgout and status are allocated in
  184. * this memory too (at separate cache lines). TOTAL_MEM_SIZE
  185. * represents the total size of this area */
  186. #define MSG_ARRAY_SIZE 8
  187. #define MSGOUT_OFFSET (L1_CACHE_ALIGN(sizeof(SCRIPT)))
  188. __u8 *msgout;
  189. #define MSGIN_OFFSET (MSGOUT_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
  190. __u8 *msgin;
  191. #define STATUS_OFFSET (MSGIN_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
  192. __u8 *status;
  193. #define SLOTS_OFFSET (STATUS_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
  194. struct NCR_700_command_slot *slots;
  195. #define TOTAL_MEM_SIZE (SLOTS_OFFSET + L1_CACHE_ALIGN(sizeof(struct NCR_700_command_slot) * NCR_700_COMMAND_SLOTS_PER_HOST))
  196. int saved_slot_position;
  197. int command_slot_count; /* protected by state lock */
  198. __u8 tag_negotiated;
  199. __u8 rev;
  200. __u8 reselection_id;
  201. __u8 min_period;
  202. /* Free list, singly linked by ITL_forw elements */
  203. struct NCR_700_command_slot *free_list;
  204. /* Completion for waited for ops, like reset, abort or
  205. * device reset.
  206. *
  207. * NOTE: relies on single threading in the error handler to
  208. * have only one outstanding at once */
  209. struct completion *eh_complete;
  210. };
  211. /*
  212. * 53C700 Register Interface - the offset from the Selected base
  213. * I/O address */
  214. #ifdef CONFIG_53C700_LE_ON_BE
  215. #define bE (hostdata->force_le_on_be ? 0 : 3)
  216. #define bSWAP (hostdata->force_le_on_be)
  217. #define bEBus (!hostdata->force_le_on_be)
  218. #elif defined(__BIG_ENDIAN)
  219. #define bE 3
  220. #define bSWAP 0
  221. #elif defined(__LITTLE_ENDIAN)
  222. #define bE 0
  223. #define bSWAP 0
  224. #else
  225. #error "__BIG_ENDIAN or __LITTLE_ENDIAN must be defined, did you include byteorder.h?"
  226. #endif
  227. #ifndef bEBus
  228. #ifdef CONFIG_53C700_BE_BUS
  229. #define bEBus 1
  230. #else
  231. #define bEBus 0
  232. #endif
  233. #endif
  234. #define bS_to_cpu(x) (bSWAP ? le32_to_cpu(x) : (x))
  235. #define bS_to_host(x) (bSWAP ? cpu_to_le32(x) : (x))
  236. /* NOTE: These registers are in the LE register space only, the required byte
  237. * swapping is done by the NCR_700_{read|write}[b] functions */
  238. #define SCNTL0_REG 0x00
  239. #define FULL_ARBITRATION 0xc0
  240. #define PARITY 0x08
  241. #define ENABLE_PARITY 0x04
  242. #define AUTO_ATN 0x02
  243. #define SCNTL1_REG 0x01
  244. #define SLOW_BUS 0x80
  245. #define ENABLE_SELECT 0x20
  246. #define ASSERT_RST 0x08
  247. #define ASSERT_EVEN_PARITY 0x04
  248. #define SDID_REG 0x02
  249. #define SIEN_REG 0x03
  250. #define PHASE_MM_INT 0x80
  251. #define FUNC_COMP_INT 0x40
  252. #define SEL_TIMEOUT_INT 0x20
  253. #define SELECT_INT 0x10
  254. #define GROSS_ERR_INT 0x08
  255. #define UX_DISC_INT 0x04
  256. #define RST_INT 0x02
  257. #define PAR_ERR_INT 0x01
  258. #define SCID_REG 0x04
  259. #define SXFER_REG 0x05
  260. #define ASYNC_OPERATION 0x00
  261. #define SODL_REG 0x06
  262. #define SOCL_REG 0x07
  263. #define SFBR_REG 0x08
  264. #define SIDL_REG 0x09
  265. #define SBDL_REG 0x0A
  266. #define SBCL_REG 0x0B
  267. /* read bits */
  268. #define SBCL_IO 0x01
  269. /*write bits */
  270. #define SYNC_DIV_AS_ASYNC 0x00
  271. #define SYNC_DIV_1_0 0x01
  272. #define SYNC_DIV_1_5 0x02
  273. #define SYNC_DIV_2_0 0x03
  274. #define DSTAT_REG 0x0C
  275. #define ILGL_INST_DETECTED 0x01
  276. #define WATCH_DOG_INTERRUPT 0x02
  277. #define SCRIPT_INT_RECEIVED 0x04
  278. #define ABORTED 0x10
  279. #define SSTAT0_REG 0x0D
  280. #define PARITY_ERROR 0x01
  281. #define SCSI_RESET_DETECTED 0x02
  282. #define UNEXPECTED_DISCONNECT 0x04
  283. #define SCSI_GROSS_ERROR 0x08
  284. #define SELECTED 0x10
  285. #define SELECTION_TIMEOUT 0x20
  286. #define FUNCTION_COMPLETE 0x40
  287. #define PHASE_MISMATCH 0x80
  288. #define SSTAT1_REG 0x0E
  289. #define SIDL_REG_FULL 0x80
  290. #define SODR_REG_FULL 0x40
  291. #define SODL_REG_FULL 0x20
  292. #define SSTAT2_REG 0x0F
  293. #define CTEST0_REG 0x14
  294. #define BTB_TIMER_DISABLE 0x40
  295. #define CTEST1_REG 0x15
  296. #define CTEST2_REG 0x16
  297. #define CTEST3_REG 0x17
  298. #define CTEST4_REG 0x18
  299. #define DISABLE_FIFO 0x00
  300. #define SLBE 0x10
  301. #define SFWR 0x08
  302. #define BYTE_LANE0 0x04
  303. #define BYTE_LANE1 0x05
  304. #define BYTE_LANE2 0x06
  305. #define BYTE_LANE3 0x07
  306. #define SCSI_ZMODE 0x20
  307. #define ZMODE 0x40
  308. #define CTEST5_REG 0x19
  309. #define MASTER_CONTROL 0x10
  310. #define DMA_DIRECTION 0x08
  311. #define CTEST7_REG 0x1B
  312. #define BURST_DISABLE 0x80 /* 710 only */
  313. #define SEL_TIMEOUT_DISABLE 0x10 /* 710 only */
  314. #define DFP 0x08
  315. #define EVP 0x04
  316. #define DIFF 0x01
  317. #define CTEST6_REG 0x1A
  318. #define TEMP_REG 0x1C
  319. #define DFIFO_REG 0x20
  320. #define FLUSH_DMA_FIFO 0x80
  321. #define CLR_FIFO 0x40
  322. #define ISTAT_REG 0x21
  323. #define ABORT_OPERATION 0x80
  324. #define SOFTWARE_RESET_710 0x40
  325. #define DMA_INT_PENDING 0x01
  326. #define SCSI_INT_PENDING 0x02
  327. #define CONNECTED 0x08
  328. #define CTEST8_REG 0x22
  329. #define LAST_DIS_ENBL 0x01
  330. #define SHORTEN_FILTERING 0x04
  331. #define ENABLE_ACTIVE_NEGATION 0x10
  332. #define GENERATE_RECEIVE_PARITY 0x20
  333. #define CLR_FIFO_710 0x04
  334. #define FLUSH_DMA_FIFO_710 0x08
  335. #define CTEST9_REG 0x23
  336. #define DBC_REG 0x24
  337. #define DCMD_REG 0x27
  338. #define DNAD_REG 0x28
  339. #define DIEN_REG 0x39
  340. #define BUS_FAULT 0x20
  341. #define ABORT_INT 0x10
  342. #define INT_INST_INT 0x04
  343. #define WD_INT 0x02
  344. #define ILGL_INST_INT 0x01
  345. #define DCNTL_REG 0x3B
  346. #define SOFTWARE_RESET 0x01
  347. #define COMPAT_700_MODE 0x01
  348. #define SCRPTS_16BITS 0x20
  349. #define ASYNC_DIV_2_0 0x00
  350. #define ASYNC_DIV_1_5 0x40
  351. #define ASYNC_DIV_1_0 0x80
  352. #define ASYNC_DIV_3_0 0xc0
  353. #define DMODE_710_REG 0x38
  354. #define DMODE_700_REG 0x34
  355. #define BURST_LENGTH_1 0x00
  356. #define BURST_LENGTH_2 0x40
  357. #define BURST_LENGTH_4 0x80
  358. #define BURST_LENGTH_8 0xC0
  359. #define DMODE_FC1 0x10
  360. #define DMODE_FC2 0x20
  361. #define BW16 32
  362. #define MODE_286 16
  363. #define IO_XFER 8
  364. #define FIXED_ADDR 4
  365. #define DSP_REG 0x2C
  366. #define DSPS_REG 0x30
  367. /* Parameters to begin SDTR negotiations. Empirically, I find that
  368. * the 53c700-66 cannot handle an offset >8, so don't change this */
  369. #define NCR_700_MAX_OFFSET 8
  370. /* Was hoping the max offset would be greater for the 710, but
  371. * empirically it seems to be 8 also */
  372. #define NCR_710_MAX_OFFSET 8
  373. #define NCR_700_MIN_XFERP 1
  374. #define NCR_710_MIN_XFERP 0
  375. #define NCR_700_MIN_PERIOD 25 /* for SDTR message, 100ns */
  376. #define script_patch_32(script, symbol, value) \
  377. { \
  378. int i; \
  379. for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
  380. __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]) + value; \
  381. (script)[A_##symbol##_used[i]] = bS_to_host(val); \
  382. dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
  383. DEBUG((" script, patching %s at %d to 0x%lx\n", \
  384. #symbol, A_##symbol##_used[i], (value))); \
  385. } \
  386. }
  387. #define script_patch_32_abs(script, symbol, value) \
  388. { \
  389. int i; \
  390. for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
  391. (script)[A_##symbol##_used[i]] = bS_to_host(value); \
  392. dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
  393. DEBUG((" script, patching %s at %d to 0x%lx\n", \
  394. #symbol, A_##symbol##_used[i], (value))); \
  395. } \
  396. }
  397. /* Used for patching the SCSI ID in the SELECT instruction */
  398. #define script_patch_ID(script, symbol, value) \
  399. { \
  400. int i; \
  401. for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
  402. __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
  403. val &= 0xff00ffff; \
  404. val |= ((value) & 0xff) << 16; \
  405. (script)[A_##symbol##_used[i]] = bS_to_host(val); \
  406. dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
  407. DEBUG((" script, patching ID field %s at %d to 0x%x\n", \
  408. #symbol, A_##symbol##_used[i], val)); \
  409. } \
  410. }
  411. #define script_patch_16(script, symbol, value) \
  412. { \
  413. int i; \
  414. for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
  415. __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
  416. val &= 0xffff0000; \
  417. val |= ((value) & 0xffff); \
  418. (script)[A_##symbol##_used[i]] = bS_to_host(val); \
  419. dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
  420. DEBUG((" script, patching short field %s at %d to 0x%x\n", \
  421. #symbol, A_##symbol##_used[i], val)); \
  422. } \
  423. }
  424. static inline __u8
  425. NCR_700_readb(struct Scsi_Host *host, __u32 reg)
  426. {
  427. const struct NCR_700_Host_Parameters *hostdata
  428. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  429. return ioread8(hostdata->base + (reg^bE));
  430. }
  431. static inline __u32
  432. NCR_700_readl(struct Scsi_Host *host, __u32 reg)
  433. {
  434. const struct NCR_700_Host_Parameters *hostdata
  435. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  436. __u32 value = bEBus ? ioread32be(hostdata->base + reg) :
  437. ioread32(hostdata->base + reg);
  438. #if 1
  439. /* sanity check the register */
  440. if((reg & 0x3) != 0)
  441. BUG();
  442. #endif
  443. return value;
  444. }
  445. static inline void
  446. NCR_700_writeb(__u8 value, struct Scsi_Host *host, __u32 reg)
  447. {
  448. const struct NCR_700_Host_Parameters *hostdata
  449. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  450. iowrite8(value, hostdata->base + (reg^bE));
  451. }
  452. static inline void
  453. NCR_700_writel(__u32 value, struct Scsi_Host *host, __u32 reg)
  454. {
  455. const struct NCR_700_Host_Parameters *hostdata
  456. = (struct NCR_700_Host_Parameters *)host->hostdata[0];
  457. #if 1
  458. /* sanity check the register */
  459. if((reg & 0x3) != 0)
  460. BUG();
  461. #endif
  462. bEBus ? iowrite32be(value, hostdata->base + reg):
  463. iowrite32(value, hostdata->base + reg);
  464. }
  465. #endif