soc.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /* soc.h: Definitions for Sparc SUNW,soc Fibre Channel Sbus driver.
  2. *
  3. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  4. */
  5. #ifndef __SOC_H
  6. #define __SOC_H
  7. #include "fc.h"
  8. #include "fcp.h"
  9. #include "fcp_impl.h"
  10. /* Hardware register offsets and constants first {{{ */
  11. #define CFG 0x00UL /* Config Register */
  12. #define SAE 0x04UL /* Slave Access Error Register */
  13. #define CMD 0x08UL /* Command and Status Register */
  14. #define IMASK 0x0cUL /* Interrupt Mask Register */
  15. /* Config Register */
  16. #define SOC_CFG_EXT_RAM_BANK_MASK 0x07000000
  17. #define SOC_CFG_EEPROM_BANK_MASK 0x00030000
  18. #define SOC_CFG_BURST64_MASK 0x00000700
  19. #define SOC_CFG_SBUS_PARITY_TEST 0x00000020
  20. #define SOC_CFG_SBUS_PARITY_CHECK 0x00000010
  21. #define SOC_CFG_SBUS_ENHANCED 0x00000008
  22. #define SOC_CFG_BURST_MASK 0x00000007
  23. /* Bursts */
  24. #define SOC_CFG_BURST_4 0x00000000
  25. #define SOC_CFG_BURST_16 0x00000004
  26. #define SOC_CFG_BURST_32 0x00000005
  27. #define SOC_CFG_BURST_64 0x00000006
  28. /* Slave Access Error Register */
  29. #define SOC_SAE_ALIGNMENT 0x00000004
  30. #define SOC_SAE_UNSUPPORTED 0x00000002
  31. #define SOC_SAE_PARITY 0x00000001
  32. /* Command & Status Register */
  33. #define SOC_CMD_RSP_QALL 0x000f0000
  34. #define SOC_CMD_RSP_Q0 0x00010000
  35. #define SOC_CMD_RSP_Q1 0x00020000
  36. #define SOC_CMD_RSP_Q2 0x00040000
  37. #define SOC_CMD_RSP_Q3 0x00080000
  38. #define SOC_CMD_REQ_QALL 0x00000f00
  39. #define SOC_CMD_REQ_Q0 0x00000100
  40. #define SOC_CMD_REQ_Q1 0x00000200
  41. #define SOC_CMD_REQ_Q2 0x00000400
  42. #define SOC_CMD_REQ_Q3 0x00000800
  43. #define SOC_CMD_SAE 0x00000080
  44. #define SOC_CMD_INTR_PENDING 0x00000008
  45. #define SOC_CMD_NON_QUEUED 0x00000004
  46. #define SOC_CMD_IDLE 0x00000002
  47. #define SOC_CMD_SOFT_RESET 0x00000001
  48. /* Interrupt Mask Register */
  49. #define SOC_IMASK_RSP_QALL 0x000f0000
  50. #define SOC_IMASK_RSP_Q0 0x00010000
  51. #define SOC_IMASK_RSP_Q1 0x00020000
  52. #define SOC_IMASK_RSP_Q2 0x00040000
  53. #define SOC_IMASK_RSP_Q3 0x00080000
  54. #define SOC_IMASK_REQ_QALL 0x00000f00
  55. #define SOC_IMASK_REQ_Q0 0x00000100
  56. #define SOC_IMASK_REQ_Q1 0x00000200
  57. #define SOC_IMASK_REQ_Q2 0x00000400
  58. #define SOC_IMASK_REQ_Q3 0x00000800
  59. #define SOC_IMASK_SAE 0x00000080
  60. #define SOC_IMASK_NON_QUEUED 0x00000004
  61. #define SOC_INTR(s, cmd) \
  62. (((cmd & SOC_CMD_RSP_QALL) | ((~cmd) & SOC_CMD_REQ_QALL)) \
  63. & s->imask)
  64. #define SOC_SETIMASK(s, i) \
  65. do { (s)->imask = (i); \
  66. sbus_writel((i), (s)->regs + IMASK); \
  67. } while(0)
  68. /* XRAM
  69. *
  70. * This is a 64KB register area. It accepts only halfword access.
  71. * That's why here are the following inline functions...
  72. */
  73. typedef void __iomem *xram_p;
  74. /* Get 32bit number from XRAM */
  75. static inline u32 xram_get_32(xram_p x)
  76. {
  77. return ((sbus_readw(x + 0x00UL) << 16) |
  78. (sbus_readw(x + 0x02UL)));
  79. }
  80. /* Like the above, but when we don't care about the high 16 bits */
  81. static inline u32 xram_get_32low(xram_p x)
  82. {
  83. return (u32) sbus_readw(x + 0x02UL);
  84. }
  85. static inline u16 xram_get_16(xram_p x)
  86. {
  87. return sbus_readw(x);
  88. }
  89. static inline u8 xram_get_8(xram_p x)
  90. {
  91. if ((unsigned long)x & 0x1UL) {
  92. x = x - 1;
  93. return (u8) sbus_readw(x);
  94. } else {
  95. return (u8) (sbus_readw(x) >> 8);
  96. }
  97. }
  98. static inline void xram_copy_from(void *p, xram_p x, int len)
  99. {
  100. for (len >>= 2; len > 0; len--, x += sizeof(u32)) {
  101. u32 val, *p32 = p;
  102. val = ((sbus_readw(x + 0x00UL) << 16) |
  103. (sbus_readw(x + 0x02UL)));
  104. *p32++ = val;
  105. p = p32;
  106. }
  107. }
  108. static inline void xram_copy_to(xram_p x, void *p, int len)
  109. {
  110. for (len >>= 2; len > 0; len--, x += sizeof(u32)) {
  111. u32 tmp, *p32 = p;
  112. tmp = *p32++;
  113. p = p32;
  114. sbus_writew(tmp >> 16, x + 0x00UL);
  115. sbus_writew(tmp, x + 0x02UL);
  116. }
  117. }
  118. static inline void xram_bzero(xram_p x, int len)
  119. {
  120. for (len >>= 1; len > 0; len--, x += sizeof(u16))
  121. sbus_writew(0, x);
  122. }
  123. /* Circular Queue */
  124. #define SOC_CQ_REQ_OFFSET (0x100 * sizeof(u16))
  125. #define SOC_CQ_RSP_OFFSET (0x110 * sizeof(u16))
  126. typedef struct {
  127. u32 address;
  128. u8 in;
  129. u8 out;
  130. u8 last;
  131. u8 seqno;
  132. } soc_hw_cq;
  133. #define SOC_PORT_A 0x0000 /* From/To Port A */
  134. #define SOC_PORT_B 0x0001 /* From/To Port A */
  135. #define SOC_FC_HDR 0x0002 /* Contains FC Header */
  136. #define SOC_NORSP 0x0004 /* Don't generate response nor interrupt */
  137. #define SOC_NOINT 0x0008 /* Generate response but not interrupt */
  138. #define SOC_XFERRDY 0x0010 /* Generate XFERRDY */
  139. #define SOC_IGNOREPARAM 0x0020 /* Ignore PARAM field in the FC header */
  140. #define SOC_COMPLETE 0x0040 /* Command completed */
  141. #define SOC_UNSOLICITED 0x0080 /* For request this is the packet to establish unsolicited pools, */
  142. /* for rsp this is unsolicited packet */
  143. #define SOC_STATUS 0x0100 /* State change (on/off line) */
  144. typedef struct {
  145. u32 token;
  146. u16 flags;
  147. u8 class;
  148. u8 segcnt;
  149. u32 bytecnt;
  150. } soc_hdr;
  151. typedef struct {
  152. u32 base;
  153. u32 count;
  154. } soc_data;
  155. #define SOC_CQTYPE_OUTBOUND 0x01
  156. #define SOC_CQTYPE_INBOUND 0x02
  157. #define SOC_CQTYPE_SIMPLE 0x03
  158. #define SOC_CQTYPE_IO_WRITE 0x04
  159. #define SOC_CQTYPE_IO_READ 0x05
  160. #define SOC_CQTYPE_UNSOLICITED 0x06
  161. #define SOC_CQTYPE_DIAG 0x07
  162. #define SOC_CQTYPE_OFFLINE 0x08
  163. #define SOC_CQTYPE_RESPONSE 0x10
  164. #define SOC_CQTYPE_INLINE 0x20
  165. #define SOC_CQFLAGS_CONT 0x01
  166. #define SOC_CQFLAGS_FULL 0x02
  167. #define SOC_CQFLAGS_BADHDR 0x04
  168. #define SOC_CQFLAGS_BADPKT 0x08
  169. typedef struct {
  170. soc_hdr shdr;
  171. soc_data data[3];
  172. fc_hdr fchdr;
  173. u8 count;
  174. u8 type;
  175. u8 flags;
  176. u8 seqno;
  177. } soc_req;
  178. #define SOC_OK 0
  179. #define SOC_P_RJT 2
  180. #define SOC_F_RJT 3
  181. #define SOC_P_BSY 4
  182. #define SOC_F_BSY 5
  183. #define SOC_ONLINE 0x10
  184. #define SOC_OFFLINE 0x11
  185. #define SOC_TIMEOUT 0x12
  186. #define SOC_OVERRUN 0x13
  187. #define SOC_UNKOWN_CQ_TYPE 0x20
  188. #define SOC_BAD_SEG_CNT 0x21
  189. #define SOC_MAX_XCHG_EXCEEDED 0x22
  190. #define SOC_BAD_XID 0x23
  191. #define SOC_XCHG_BUSY 0x24
  192. #define SOC_BAD_POOL_ID 0x25
  193. #define SOC_INSUFFICIENT_CQES 0x26
  194. #define SOC_ALLOC_FAIL 0x27
  195. #define SOC_BAD_SID 0x28
  196. #define SOC_NO_SEG_INIT 0x29
  197. typedef struct {
  198. soc_hdr shdr;
  199. u32 status;
  200. soc_data data;
  201. u8 xxx1[12];
  202. fc_hdr fchdr;
  203. u8 count;
  204. u8 type;
  205. u8 flags;
  206. u8 seqno;
  207. } soc_rsp;
  208. /* }}} */
  209. /* Now our software structures and constants we use to drive the beast {{{ */
  210. #define SOC_CQ_REQ0_SIZE 4
  211. #define SOC_CQ_REQ1_SIZE 64
  212. #define SOC_CQ_RSP0_SIZE 8
  213. #define SOC_CQ_RSP1_SIZE 4
  214. #define SOC_SOLICITED_RSP_Q 0
  215. #define SOC_UNSOLICITED_RSP_Q 1
  216. struct soc;
  217. typedef struct {
  218. /* This must come first */
  219. fc_channel fc;
  220. struct soc *s;
  221. u16 flags;
  222. u16 mask;
  223. } soc_port;
  224. typedef struct {
  225. soc_hw_cq __iomem *hw_cq; /* Related XRAM cq */
  226. soc_req __iomem *pool;
  227. u8 in;
  228. u8 out;
  229. u8 last;
  230. u8 seqno;
  231. } soc_cq_rsp;
  232. typedef struct {
  233. soc_hw_cq __iomem *hw_cq; /* Related XRAM cq */
  234. soc_req *pool;
  235. u8 in;
  236. u8 out;
  237. u8 last;
  238. u8 seqno;
  239. } soc_cq_req;
  240. struct soc {
  241. spinlock_t lock;
  242. soc_port port[2]; /* Every SOC has one or two FC ports */
  243. soc_cq_req req[2]; /* Request CQs */
  244. soc_cq_rsp rsp[2]; /* Response CQs */
  245. int soc_no;
  246. void __iomem *regs;
  247. xram_p xram;
  248. fc_wwn wwn;
  249. u32 imask; /* Our copy of regs->imask */
  250. u32 cfg; /* Our copy of regs->cfg */
  251. char serv_params[80];
  252. struct soc *next;
  253. int curr_port; /* Which port will have priority to fcp_queue_empty */
  254. soc_req *req_cpu;
  255. u32 req_dvma;
  256. };
  257. /* }}} */
  258. #endif /* !(__SOC_H) */