fmn.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /*
  2. * Copyright (c) 2003-2012 Broadcom Corporation
  3. * All Rights Reserved
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the Broadcom
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _NLM_FMN_H_
  35. #define _NLM_FMN_H_
  36. #include <asm/netlogic/mips-extns.h> /* for COP2 access */
  37. /* Station IDs */
  38. #define FMN_STNID_CPU0 0x00
  39. #define FMN_STNID_CPU1 0x08
  40. #define FMN_STNID_CPU2 0x10
  41. #define FMN_STNID_CPU3 0x18
  42. #define FMN_STNID_CPU4 0x20
  43. #define FMN_STNID_CPU5 0x28
  44. #define FMN_STNID_CPU6 0x30
  45. #define FMN_STNID_CPU7 0x38
  46. #define FMN_STNID_XGS0_TX 64
  47. #define FMN_STNID_XMAC0_00_TX 64
  48. #define FMN_STNID_XMAC0_01_TX 65
  49. #define FMN_STNID_XMAC0_02_TX 66
  50. #define FMN_STNID_XMAC0_03_TX 67
  51. #define FMN_STNID_XMAC0_04_TX 68
  52. #define FMN_STNID_XMAC0_05_TX 69
  53. #define FMN_STNID_XMAC0_06_TX 70
  54. #define FMN_STNID_XMAC0_07_TX 71
  55. #define FMN_STNID_XMAC0_08_TX 72
  56. #define FMN_STNID_XMAC0_09_TX 73
  57. #define FMN_STNID_XMAC0_10_TX 74
  58. #define FMN_STNID_XMAC0_11_TX 75
  59. #define FMN_STNID_XMAC0_12_TX 76
  60. #define FMN_STNID_XMAC0_13_TX 77
  61. #define FMN_STNID_XMAC0_14_TX 78
  62. #define FMN_STNID_XMAC0_15_TX 79
  63. #define FMN_STNID_XGS1_TX 80
  64. #define FMN_STNID_XMAC1_00_TX 80
  65. #define FMN_STNID_XMAC1_01_TX 81
  66. #define FMN_STNID_XMAC1_02_TX 82
  67. #define FMN_STNID_XMAC1_03_TX 83
  68. #define FMN_STNID_XMAC1_04_TX 84
  69. #define FMN_STNID_XMAC1_05_TX 85
  70. #define FMN_STNID_XMAC1_06_TX 86
  71. #define FMN_STNID_XMAC1_07_TX 87
  72. #define FMN_STNID_XMAC1_08_TX 88
  73. #define FMN_STNID_XMAC1_09_TX 89
  74. #define FMN_STNID_XMAC1_10_TX 90
  75. #define FMN_STNID_XMAC1_11_TX 91
  76. #define FMN_STNID_XMAC1_12_TX 92
  77. #define FMN_STNID_XMAC1_13_TX 93
  78. #define FMN_STNID_XMAC1_14_TX 94
  79. #define FMN_STNID_XMAC1_15_TX 95
  80. #define FMN_STNID_GMAC 96
  81. #define FMN_STNID_GMACJFR_0 96
  82. #define FMN_STNID_GMACRFR_0 97
  83. #define FMN_STNID_GMACTX0 98
  84. #define FMN_STNID_GMACTX1 99
  85. #define FMN_STNID_GMACTX2 100
  86. #define FMN_STNID_GMACTX3 101
  87. #define FMN_STNID_GMACJFR_1 102
  88. #define FMN_STNID_GMACRFR_1 103
  89. #define FMN_STNID_DMA 104
  90. #define FMN_STNID_DMA_0 104
  91. #define FMN_STNID_DMA_1 105
  92. #define FMN_STNID_DMA_2 106
  93. #define FMN_STNID_DMA_3 107
  94. #define FMN_STNID_XGS0FR 112
  95. #define FMN_STNID_XMAC0JFR 112
  96. #define FMN_STNID_XMAC0RFR 113
  97. #define FMN_STNID_XGS1FR 114
  98. #define FMN_STNID_XMAC1JFR 114
  99. #define FMN_STNID_XMAC1RFR 115
  100. #define FMN_STNID_SEC 120
  101. #define FMN_STNID_SEC0 120
  102. #define FMN_STNID_SEC1 121
  103. #define FMN_STNID_SEC2 122
  104. #define FMN_STNID_SEC3 123
  105. #define FMN_STNID_PK0 124
  106. #define FMN_STNID_SEC_RSA 124
  107. #define FMN_STNID_SEC_RSVD0 125
  108. #define FMN_STNID_SEC_RSVD1 126
  109. #define FMN_STNID_SEC_RSVD2 127
  110. #define FMN_STNID_GMAC1 80
  111. #define FMN_STNID_GMAC1_FR_0 81
  112. #define FMN_STNID_GMAC1_TX0 82
  113. #define FMN_STNID_GMAC1_TX1 83
  114. #define FMN_STNID_GMAC1_TX2 84
  115. #define FMN_STNID_GMAC1_TX3 85
  116. #define FMN_STNID_GMAC1_FR_1 87
  117. #define FMN_STNID_GMAC0 96
  118. #define FMN_STNID_GMAC0_FR_0 97
  119. #define FMN_STNID_GMAC0_TX0 98
  120. #define FMN_STNID_GMAC0_TX1 99
  121. #define FMN_STNID_GMAC0_TX2 100
  122. #define FMN_STNID_GMAC0_TX3 101
  123. #define FMN_STNID_GMAC0_FR_1 103
  124. #define FMN_STNID_CMP_0 108
  125. #define FMN_STNID_CMP_1 109
  126. #define FMN_STNID_CMP_2 110
  127. #define FMN_STNID_CMP_3 111
  128. #define FMN_STNID_PCIE_0 116
  129. #define FMN_STNID_PCIE_1 117
  130. #define FMN_STNID_PCIE_2 118
  131. #define FMN_STNID_PCIE_3 119
  132. #define FMN_STNID_XLS_PK0 121
  133. #define nlm_read_c2_cc0(s) __read_32bit_c2_register($16, s)
  134. #define nlm_read_c2_cc1(s) __read_32bit_c2_register($17, s)
  135. #define nlm_read_c2_cc2(s) __read_32bit_c2_register($18, s)
  136. #define nlm_read_c2_cc3(s) __read_32bit_c2_register($19, s)
  137. #define nlm_read_c2_cc4(s) __read_32bit_c2_register($20, s)
  138. #define nlm_read_c2_cc5(s) __read_32bit_c2_register($21, s)
  139. #define nlm_read_c2_cc6(s) __read_32bit_c2_register($22, s)
  140. #define nlm_read_c2_cc7(s) __read_32bit_c2_register($23, s)
  141. #define nlm_read_c2_cc8(s) __read_32bit_c2_register($24, s)
  142. #define nlm_read_c2_cc9(s) __read_32bit_c2_register($25, s)
  143. #define nlm_read_c2_cc10(s) __read_32bit_c2_register($26, s)
  144. #define nlm_read_c2_cc11(s) __read_32bit_c2_register($27, s)
  145. #define nlm_read_c2_cc12(s) __read_32bit_c2_register($28, s)
  146. #define nlm_read_c2_cc13(s) __read_32bit_c2_register($29, s)
  147. #define nlm_read_c2_cc14(s) __read_32bit_c2_register($30, s)
  148. #define nlm_read_c2_cc15(s) __read_32bit_c2_register($31, s)
  149. #define nlm_write_c2_cc0(s, v) __write_32bit_c2_register($16, s, v)
  150. #define nlm_write_c2_cc1(s, v) __write_32bit_c2_register($17, s, v)
  151. #define nlm_write_c2_cc2(s, v) __write_32bit_c2_register($18, s, v)
  152. #define nlm_write_c2_cc3(s, v) __write_32bit_c2_register($19, s, v)
  153. #define nlm_write_c2_cc4(s, v) __write_32bit_c2_register($20, s, v)
  154. #define nlm_write_c2_cc5(s, v) __write_32bit_c2_register($21, s, v)
  155. #define nlm_write_c2_cc6(s, v) __write_32bit_c2_register($22, s, v)
  156. #define nlm_write_c2_cc7(s, v) __write_32bit_c2_register($23, s, v)
  157. #define nlm_write_c2_cc8(s, v) __write_32bit_c2_register($24, s, v)
  158. #define nlm_write_c2_cc9(s, v) __write_32bit_c2_register($25, s, v)
  159. #define nlm_write_c2_cc10(s, v) __write_32bit_c2_register($26, s, v)
  160. #define nlm_write_c2_cc11(s, v) __write_32bit_c2_register($27, s, v)
  161. #define nlm_write_c2_cc12(s, v) __write_32bit_c2_register($28, s, v)
  162. #define nlm_write_c2_cc13(s, v) __write_32bit_c2_register($29, s, v)
  163. #define nlm_write_c2_cc14(s, v) __write_32bit_c2_register($30, s, v)
  164. #define nlm_write_c2_cc15(s, v) __write_32bit_c2_register($31, s, v)
  165. #define nlm_read_c2_status(sel) __read_32bit_c2_register($2, 0)
  166. #define nlm_read_c2_config() __read_32bit_c2_register($3, 0)
  167. #define nlm_write_c2_config(v) __write_32bit_c2_register($3, 0, v)
  168. #define nlm_read_c2_bucksize(b) __read_32bit_c2_register($4, b)
  169. #define nlm_write_c2_bucksize(b, v) __write_32bit_c2_register($4, b, v)
  170. #define nlm_read_c2_rx_msg0() __read_64bit_c2_register($1, 0)
  171. #define nlm_read_c2_rx_msg1() __read_64bit_c2_register($1, 1)
  172. #define nlm_read_c2_rx_msg2() __read_64bit_c2_register($1, 2)
  173. #define nlm_read_c2_rx_msg3() __read_64bit_c2_register($1, 3)
  174. #define nlm_write_c2_tx_msg0(v) __write_64bit_c2_register($0, 0, v)
  175. #define nlm_write_c2_tx_msg1(v) __write_64bit_c2_register($0, 1, v)
  176. #define nlm_write_c2_tx_msg2(v) __write_64bit_c2_register($0, 2, v)
  177. #define nlm_write_c2_tx_msg3(v) __write_64bit_c2_register($0, 3, v)
  178. #define FMN_STN_RX_QSIZE 256
  179. #define FMN_NSTATIONS 128
  180. #define FMN_CORE_NBUCKETS 8
  181. static inline void nlm_msgsnd(unsigned int stid)
  182. {
  183. __asm__ volatile (
  184. ".set push\n"
  185. ".set noreorder\n"
  186. ".set noat\n"
  187. "move $1, %0\n"
  188. "c2 0x10001\n" /* msgsnd $1 */
  189. ".set pop\n"
  190. : : "r" (stid) : "$1"
  191. );
  192. }
  193. static inline void nlm_msgld(unsigned int pri)
  194. {
  195. __asm__ volatile (
  196. ".set push\n"
  197. ".set noreorder\n"
  198. ".set noat\n"
  199. "move $1, %0\n"
  200. "c2 0x10002\n" /* msgld $1 */
  201. ".set pop\n"
  202. : : "r" (pri) : "$1"
  203. );
  204. }
  205. static inline void nlm_msgwait(unsigned int mask)
  206. {
  207. __asm__ volatile (
  208. ".set push\n"
  209. ".set noreorder\n"
  210. ".set noat\n"
  211. "move $8, %0\n"
  212. "c2 0x10003\n" /* msgwait $1 */
  213. ".set pop\n"
  214. : : "r" (mask) : "$1"
  215. );
  216. }
  217. /*
  218. * Disable interrupts and enable COP2 access
  219. */
  220. static inline uint32_t nlm_cop2_enable(void)
  221. {
  222. uint32_t sr = read_c0_status();
  223. write_c0_status((sr & ~ST0_IE) | ST0_CU2);
  224. return sr;
  225. }
  226. static inline void nlm_cop2_restore(uint32_t sr)
  227. {
  228. write_c0_status(sr);
  229. }
  230. static inline void nlm_fmn_setup_intr(int irq, unsigned int tmask)
  231. {
  232. uint32_t config;
  233. config = (1 << 24) /* interrupt water mark - 1 msg */
  234. | (irq << 16) /* irq */
  235. | (tmask << 8) /* thread mask */
  236. | 0x2; /* enable watermark intr, disable empty intr */
  237. nlm_write_c2_config(config);
  238. }
  239. struct nlm_fmn_msg {
  240. uint64_t msg0;
  241. uint64_t msg1;
  242. uint64_t msg2;
  243. uint64_t msg3;
  244. };
  245. static inline int nlm_fmn_send(unsigned int size, unsigned int code,
  246. unsigned int stid, struct nlm_fmn_msg *msg)
  247. {
  248. unsigned int dest;
  249. uint32_t status;
  250. int i;
  251. /*
  252. * Make sure that all the writes pending at the cpu are flushed.
  253. * Any writes pending on CPU will not be see by devices. L1/L2
  254. * caches are coherent with IO, so no cache flush needed.
  255. */
  256. __asm __volatile("sync");
  257. /* Load TX message buffers */
  258. nlm_write_c2_tx_msg0(msg->msg0);
  259. nlm_write_c2_tx_msg1(msg->msg1);
  260. nlm_write_c2_tx_msg2(msg->msg2);
  261. nlm_write_c2_tx_msg3(msg->msg3);
  262. dest = ((size - 1) << 16) | (code << 8) | stid;
  263. /*
  264. * Retry a few times on credit fail, this should be a
  265. * transient condition, unless there is a configuration
  266. * failure, or the receiver is stuck.
  267. */
  268. for (i = 0; i < 8; i++) {
  269. nlm_msgsnd(dest);
  270. status = nlm_read_c2_status(0);
  271. if ((status & 0x2) == 1)
  272. pr_info("Send pending fail!\n");
  273. if ((status & 0x4) == 0)
  274. return 0;
  275. }
  276. /* If there is a credit failure, return error */
  277. return status & 0x06;
  278. }
  279. static inline int nlm_fmn_receive(int bucket, int *size, int *code, int *stid,
  280. struct nlm_fmn_msg *msg)
  281. {
  282. uint32_t status, tmp;
  283. nlm_msgld(bucket);
  284. /* wait for load pending to clear */
  285. do {
  286. status = nlm_read_c2_status(1);
  287. } while ((status & 0x08) != 0);
  288. /* receive error bits */
  289. tmp = status & 0x30;
  290. if (tmp != 0)
  291. return tmp;
  292. *size = ((status & 0xc0) >> 6) + 1;
  293. *code = (status & 0xff00) >> 8;
  294. *stid = (status & 0x7f0000) >> 16;
  295. msg->msg0 = nlm_read_c2_rx_msg0();
  296. msg->msg1 = nlm_read_c2_rx_msg1();
  297. msg->msg2 = nlm_read_c2_rx_msg2();
  298. msg->msg3 = nlm_read_c2_rx_msg3();
  299. return 0;
  300. }
  301. struct xlr_fmn_info {
  302. int num_buckets;
  303. int start_stn_id;
  304. int end_stn_id;
  305. int credit_config[128];
  306. };
  307. struct xlr_board_fmn_config {
  308. int bucket_size[128]; /* size of buckets for all stations */
  309. struct xlr_fmn_info cpu[8];
  310. struct xlr_fmn_info gmac[2];
  311. struct xlr_fmn_info dma;
  312. struct xlr_fmn_info cmp;
  313. struct xlr_fmn_info sae;
  314. struct xlr_fmn_info xgmac[2];
  315. };
  316. extern int nlm_register_fmn_handler(int start, int end,
  317. void (*fn)(int, int, int, int, struct nlm_fmn_msg *, void *),
  318. void *arg);
  319. extern void xlr_percpu_fmn_init(void);
  320. extern void nlm_setup_fmn_irq(void);
  321. extern void xlr_board_info_setup(void);
  322. extern struct xlr_board_fmn_config xlr_board_fmn_config;
  323. #endif