bte.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2000-2006 Silicon Graphics, Inc. All Rights Reserved.
  7. */
  8. #ifndef _ASM_IA64_SN_BTE_H
  9. #define _ASM_IA64_SN_BTE_H
  10. #include <linux/timer.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/cache.h>
  13. #include <asm/sn/pda.h>
  14. #include <asm/sn/types.h>
  15. #include <asm/sn/shub_mmr.h>
  16. #define IBCT_NOTIFY (0x1UL << 4)
  17. #define IBCT_ZFIL_MODE (0x1UL << 0)
  18. /* #define BTE_DEBUG */
  19. /* #define BTE_DEBUG_VERBOSE */
  20. #ifdef BTE_DEBUG
  21. # define BTE_PRINTK(x) printk x /* Terse */
  22. # ifdef BTE_DEBUG_VERBOSE
  23. # define BTE_PRINTKV(x) printk x /* Verbose */
  24. # else
  25. # define BTE_PRINTKV(x)
  26. # endif /* BTE_DEBUG_VERBOSE */
  27. #else
  28. # define BTE_PRINTK(x)
  29. # define BTE_PRINTKV(x)
  30. #endif /* BTE_DEBUG */
  31. /* BTE status register only supports 16 bits for length field */
  32. #define BTE_LEN_BITS (16)
  33. #define BTE_LEN_MASK ((1 << BTE_LEN_BITS) - 1)
  34. #define BTE_MAX_XFER ((1 << BTE_LEN_BITS) * L1_CACHE_BYTES)
  35. /* Define hardware */
  36. #define BTES_PER_NODE (is_shub2() ? 4 : 2)
  37. #define MAX_BTES_PER_NODE 4
  38. #define BTE2OFF_CTRL 0
  39. #define BTE2OFF_SRC (SH2_BT_ENG_SRC_ADDR_0 - SH2_BT_ENG_CSR_0)
  40. #define BTE2OFF_DEST (SH2_BT_ENG_DEST_ADDR_0 - SH2_BT_ENG_CSR_0)
  41. #define BTE2OFF_NOTIFY (SH2_BT_ENG_NOTIF_ADDR_0 - SH2_BT_ENG_CSR_0)
  42. #define BTE_BASE_ADDR(interface) \
  43. (is_shub2() ? (interface == 0) ? SH2_BT_ENG_CSR_0 : \
  44. (interface == 1) ? SH2_BT_ENG_CSR_1 : \
  45. (interface == 2) ? SH2_BT_ENG_CSR_2 : \
  46. SH2_BT_ENG_CSR_3 \
  47. : (interface == 0) ? IIO_IBLS0 : IIO_IBLS1)
  48. #define BTE_SOURCE_ADDR(base) \
  49. (is_shub2() ? base + (BTE2OFF_SRC/8) \
  50. : base + (BTEOFF_SRC/8))
  51. #define BTE_DEST_ADDR(base) \
  52. (is_shub2() ? base + (BTE2OFF_DEST/8) \
  53. : base + (BTEOFF_DEST/8))
  54. #define BTE_CTRL_ADDR(base) \
  55. (is_shub2() ? base + (BTE2OFF_CTRL/8) \
  56. : base + (BTEOFF_CTRL/8))
  57. #define BTE_NOTIF_ADDR(base) \
  58. (is_shub2() ? base + (BTE2OFF_NOTIFY/8) \
  59. : base + (BTEOFF_NOTIFY/8))
  60. /* Define hardware modes */
  61. #define BTE_NOTIFY IBCT_NOTIFY
  62. #define BTE_NORMAL BTE_NOTIFY
  63. #define BTE_ZERO_FILL (BTE_NOTIFY | IBCT_ZFIL_MODE)
  64. /* Use a reserved bit to let the caller specify a wait for any BTE */
  65. #define BTE_WACQUIRE 0x4000
  66. /* Use the BTE on the node with the destination memory */
  67. #define BTE_USE_DEST (BTE_WACQUIRE << 1)
  68. /* Use any available BTE interface on any node for the transfer */
  69. #define BTE_USE_ANY (BTE_USE_DEST << 1)
  70. /* macro to force the IBCT0 value valid */
  71. #define BTE_VALID_MODE(x) ((x) & (IBCT_NOTIFY | IBCT_ZFIL_MODE))
  72. #define BTE_ACTIVE (IBLS_BUSY | IBLS_ERROR)
  73. #define BTE_WORD_AVAILABLE (IBLS_BUSY << 1)
  74. #define BTE_WORD_BUSY (~BTE_WORD_AVAILABLE)
  75. /*
  76. * Some macros to simplify reading.
  77. * Start with macros to locate the BTE control registers.
  78. */
  79. #define BTE_LNSTAT_LOAD(_bte) \
  80. HUB_L(_bte->bte_base_addr)
  81. #define BTE_LNSTAT_STORE(_bte, _x) \
  82. HUB_S(_bte->bte_base_addr, (_x))
  83. #define BTE_SRC_STORE(_bte, _x) \
  84. ({ \
  85. u64 __addr = ((_x) & ~AS_MASK); \
  86. if (is_shub2()) \
  87. __addr = SH2_TIO_PHYS_TO_DMA(__addr); \
  88. HUB_S(_bte->bte_source_addr, __addr); \
  89. })
  90. #define BTE_DEST_STORE(_bte, _x) \
  91. ({ \
  92. u64 __addr = ((_x) & ~AS_MASK); \
  93. if (is_shub2()) \
  94. __addr = SH2_TIO_PHYS_TO_DMA(__addr); \
  95. HUB_S(_bte->bte_destination_addr, __addr); \
  96. })
  97. #define BTE_CTRL_STORE(_bte, _x) \
  98. HUB_S(_bte->bte_control_addr, (_x))
  99. #define BTE_NOTIF_STORE(_bte, _x) \
  100. ({ \
  101. u64 __addr = ia64_tpa((_x) & ~AS_MASK); \
  102. if (is_shub2()) \
  103. __addr = SH2_TIO_PHYS_TO_DMA(__addr); \
  104. HUB_S(_bte->bte_notify_addr, __addr); \
  105. })
  106. #define BTE_START_TRANSFER(_bte, _len, _mode) \
  107. is_shub2() ? BTE_CTRL_STORE(_bte, IBLS_BUSY | (_mode << 24) | _len) \
  108. : BTE_LNSTAT_STORE(_bte, _len); \
  109. BTE_CTRL_STORE(_bte, _mode)
  110. /* Possible results from bte_copy and bte_unaligned_copy */
  111. /* The following error codes map into the BTE hardware codes
  112. * IIO_ICRB_ECODE_* (in shubio.h). The hardware uses
  113. * an error code of 0 (IIO_ICRB_ECODE_DERR), but we want zero
  114. * to mean BTE_SUCCESS, so add one (BTEFAIL_OFFSET) to the error
  115. * codes to give the following error codes.
  116. */
  117. #define BTEFAIL_OFFSET 1
  118. typedef enum {
  119. BTE_SUCCESS, /* 0 is success */
  120. BTEFAIL_DIR, /* Directory error due to IIO access*/
  121. BTEFAIL_POISON, /* poison error on IO access (write to poison page) */
  122. BTEFAIL_WERR, /* Write error (ie WINV to a Read only line) */
  123. BTEFAIL_ACCESS, /* access error (protection violation) */
  124. BTEFAIL_PWERR, /* Partial Write Error */
  125. BTEFAIL_PRERR, /* Partial Read Error */
  126. BTEFAIL_TOUT, /* CRB Time out */
  127. BTEFAIL_XTERR, /* Incoming xtalk pkt had error bit */
  128. BTEFAIL_NOTAVAIL, /* BTE not available */
  129. } bte_result_t;
  130. /*
  131. * Structure defining a bte. An instance of this
  132. * structure is created in the nodepda for each
  133. * bte on that node (as defined by BTES_PER_NODE)
  134. * This structure contains everything necessary
  135. * to work with a BTE.
  136. */
  137. struct bteinfo_s {
  138. volatile u64 notify ____cacheline_aligned;
  139. u64 *bte_base_addr ____cacheline_aligned;
  140. u64 *bte_source_addr;
  141. u64 *bte_destination_addr;
  142. u64 *bte_control_addr;
  143. u64 *bte_notify_addr;
  144. spinlock_t spinlock;
  145. cnodeid_t bte_cnode; /* cnode */
  146. int bte_error_count; /* Number of errors encountered */
  147. int bte_num; /* 0 --> BTE0, 1 --> BTE1 */
  148. int cleanup_active; /* Interface is locked for cleanup */
  149. volatile bte_result_t bh_error; /* error while processing */
  150. volatile u64 *most_rcnt_na;
  151. struct bteinfo_s *btes_to_try[MAX_BTES_PER_NODE];
  152. };
  153. /*
  154. * Function prototypes (functions defined in bte.c, used elsewhere)
  155. */
  156. extern bte_result_t bte_copy(u64, u64, u64, u64, void *);
  157. extern bte_result_t bte_unaligned_copy(u64, u64, u64, u64);
  158. extern void bte_error_handler(unsigned long);
  159. #define bte_zero(dest, len, mode, notification) \
  160. bte_copy(0, dest, len, ((mode) | BTE_ZERO_FILL), notification)
  161. /*
  162. * The following is the prefered way of calling bte_unaligned_copy
  163. * If the copy is fully cache line aligned, then bte_copy is
  164. * used instead. Since bte_copy is inlined, this saves a call
  165. * stack. NOTE: bte_copy is called synchronously and does block
  166. * until the transfer is complete. In order to get the asynch
  167. * version of bte_copy, you must perform this check yourself.
  168. */
  169. #define BTE_UNALIGNED_COPY(src, dest, len, mode) \
  170. (((len & L1_CACHE_MASK) || (src & L1_CACHE_MASK) || \
  171. (dest & L1_CACHE_MASK)) ? \
  172. bte_unaligned_copy(src, dest, len, mode) : \
  173. bte_copy(src, dest, len, mode, NULL))
  174. #endif /* _ASM_IA64_SN_BTE_H */